How to pass arrays of integers or doubles to VBA function in Excel
Hi
Range.Value is a variant array
ie.
Dim myValues as Variant
myValues = myRange.Value
You can access it like an array
msgbox myValues(3,1)
You can get its dimensions if you need to loop through the values
myrows = UBound(myValues,1) 'number of rows
mycolumns = UBound(myValues,2) 'number of columns
For i = 1 to myrows
For j = 1 to mycolumns
msgbox myValues(i, j)
next j
next i
Your function should now accept two such variants
myfunction(myValaues1 as Variant, myValues2 as Variant)
There is a proviso: the value of a single cell is NOT a 1 by 1 array,
and you will have to handle that case if it arises.
regards
Paul
On Mar 8, 7:23 pm, Bull Earwig <Bull
wrote:
I have written a function in Excel's Visual Basic editor. It accepts two
arrays, one of Integer's and one of Double's.
The function seems to compile just fine and other functions are working well
for me, so I semi know what I am doing.
In the spreadsheet, I would like to select a range of cells and pass them as
the integer array. I would like to do the same for another contiguous range
of cells to serve as the Double array.
I tried simply doing just that but got errors in the spreadsheet.
How do I do this? Is there some function in the spreadsheet that converts a
range of cells into an array of numerical values?
Or do I need to adapt the function to work in the spreadsheet's way of doing
things and make it receive cell references from which it extracts the
numerical values?
TIA,
BE
|