I've come across a fairly weird issue and I'm wondering if I'm doing something wrong or if this is an Excel bug (using Excel 2010 for PC, BTW)... To explain, let me create a simple scenario:
I define a very simple UDF that uses properties of a Range object, for example:
Public Function SillyThing(rng As Range) As Variant SillyThing = rng.IndentLevel End FunctionI have a simple table defined in my workbook (
Table1, say) with only one row at the start:Col1: Col2: <blank> =SillyThing([@col1])I have a column of cells in, say,
Range("F2:F8")I have the following
Subdefined:Sub Macro3() Range("F2:F8").Copy Range("Table1[col1]") End Sub
Now, when I run that macro, it gives me #VALUE! error for the entire second column in my table (where the formula would get auto-filled).
However, if I use the following macro instead:
Sub Macro2()
Range("F2:F8").Select
Selection.Copy
Range("Table1[col1]").Select
ActiveSheet.Paste
End Sub
Then it works just fine!
Upon debugging, if I place a breakpoint in the UDF, I find that the Range object passed through in Macro3 has the following statement for many of its properties - : IndentLevel : <Unable to get the IndentLevel property of the Range class> : Variant : Module1.SillyThing
Obviously, I know how to fix it using the same idea as Macro2, but I'm really curious if this is a known issue or if there's something I'm missing / other workarounds I'm unfamiliar with.
Hope this makes sense!!
Thanks!!!