Hi
anyone know the best way to multiply multiple arrays?
I have 3 1D arrays W(), Wpos() & Wflag()
i want to multiply each value in the array by the corresponding value in the other arrays
any advice please?
B
Hi
anyone know the best way to multiply multiple arrays?
I have 3 1D arrays W(), Wpos() & Wflag()
i want to multiply each value in the array by the corresponding value in the other arrays
any advice please?
B
maybe use the worksheet function SUMPRODUCT(). It is designed to do just what you're describing.
Thanks Teylyn, tired this
but no avail?![]()
Sub Arraymultiply() Dim array1(), array2(), array3() As Integer Dim i As Integer For i = 1 To 4 array1(i) = Cells(i, 1) array2(1) = Cells(i, 2) array3(i) = WorksheetFunction.SumProduct(array1(i))(array2(i)) Cells(i, 3) = array3(i) Next i End Sub
What do you think
maybe would be usefull to upload example file and explain problem.
Never use Merged Cells in Excel
This
is missing several commas and a few brackets. Check your syntax.![]()
array3(i) = WorksheetFunction.SumProduct(array1(i))(array2(i))
hi Berabus,
Welcome to the Forum
I may be misunderstanding your question (or example) but... is there any particular reason why you are trying to do the multiplication in code rather than directly in the worksheet?
Doing it directly in the worksheet is likely to be much quicker than looping cell by cell, especially if your real data set is large.
From the example above, it appears that you could typeinto cell C2 & copy it down as far as you need. If you really want this in a macro, you could record a macro of your actions as you do this.![]()
=A2*B2
hth
Rob
Rob Brockett
Kiwi in the UK
Always learning & the best way to learn is to experience...
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks