Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel VBA Array Function...What's wrong?
I am just trying to create an array function that returns an array containing
the values in a source Range. It shouldn't be that difficult, right? My source is below. I am running into the problem on this line: "Result(i, j) = Source(i, j).Value". The Result element is Empty after the assignment, even though Source(i,j).Value is not Empty. Help!? If you know why this assignment isn't working or if you know a better way to do this, please let me know. Function Range2Array(Source As Range) As Variant Dim rowCount, colCount As Integer rowCount = Source.Rows.count colCount = Source.Columns.count ' Ensure target is a range equal in size to source If Not (TypeOf Application.Caller Is Range _ And Application.Caller.Columns.count = colCount _ And Application.Caller.Rows.count = rowCount _ ) Then Exit Function End If ' Load result array Dim Result() As Variant ReDim Result(1 To rowCount, 1 To colCount) As Variant Dim i, j As Integer Result(1, 1) = "Test" For i = 1 To rowCount For j = 1 To colCount ' At this point Source(i,j).Value is not Empty Result(i, j) = Source(i, j).Value ' At this point the value of Result is Empty. Next j Next i ' Return result array Test = Result End Function |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Sum + IF Array wrong sum | Excel Worksheet Functions | |||
weekday function in excel 2007 wrong | Excel Discussion (Misc queries) | |||
What's wrong with my array formula | Excel Discussion (Misc queries) | |||
What is wrong with my array? | Excel Programming | |||
Please help - What am i doing wrong with this array? | Excel Programming |