In VBA is it possible to loop through, for example, every column of a 2 dimensional array and perform and operation on each column? I would like to pass each column or row of an array sequentially to a function.
Thanks.
In VBA is it possible to loop through, for example, every column of a 2 dimensional array and perform and operation on each column? I would like to pass each column or row of an array sequentially to a function.
Thanks.
Normally I'd not answer this because you haven't shown any effort in trying.. But I've had my own difficulty with this (with my own question currently posted looking for a better solution) and I'm bored so:
if you have a 2D array named myArr like this:
1,2,3,4,5
6,7,8,9,10
11,12,13,14,15
defined by: dim myArr(2,4) as variant
then you could loop through it with a double loop like this:
For i = LBound(myArr) To UBound(myArr)
For j = LBound(myArr, 2) To UBound(myArr, 2)
temp(j) = myArr(i, j)
Next
Next
where temp is defined and reDim'd like this:
dim temp() as variant
redim temp(lbound(myArr,2), ubound(myArr,2)) 'note the ",2" gets the bounds of the 2nd dimention
and then pass temp to a function: FunctionName(Temp)
So put that together by sticking thue function call after the inner loop and it would loop through and pass temp to the function for each row