Suppose we are given two variants, X
and Y
, that may be numbers, ranges or arrays.
Is there a simple way to add or multiply them like in worksheet formulas =X+Y
and =X*Y
?
One possibility i thought of would be to use the Evaluate operation, something like this:
Dim X, Y
Sub AddMult()
Dim Add, Mult
X = Array(Array(1, 3), Array(2, 4))
Y = Array(1, 2)
Add = [GetX()+GetY()]
Mult = [GetX()*GetY()]
End Sub
Function GetX()
GetX = X
End Function
Function GetY()
GetY = Y
End Function
It seems a little awkward though. Any other ideas?
(Here is a related question: Multiplying arrays with scalars and adding in VBA.)