Array multiplication in VBA
there are no array operators or array functions in VBA. You would need to
loop.
if you want to use worksheet functions
Sub ArrayMult()
For i = 1 To 10
Range("A1")(i).Value = i
Range("B1")(i).Value = i ^ 2
Next
varr = Application.MMult( _
Range("A1:A10"), Application.Transpose( _
Range("B1:B10")))
For i = LBound(varr, 2) To UBound(varr, 2)
Debug.Print varr(1, i)
Next
End Sub
--
Regards.
Tom Ogilvy
Dan E wrote in message
...
I am trying to simulate the behaviour of an array multiplication such as
{=(A1:A10)*(B1:B10)} in VBA. The resulting array should contain:
={A1*B1, A2*B2, . . . , A10*B10}.
I was hoping to avoid writing a loop if it is at all possible?
I don't think there is a worksheetfunction which does this and I was
hoping to avoid the loop:
For i = 0 to Ubound(Temp1)
Temp3(i) = Temp1(i)*Temp2(i)
Next
Is there an easy way to do this?
Dan E
|