Need a formula to multiply arrays

sriman

New Member
Joined
Jun 16, 2011
Messages
5
I have values in columns A1, B1, C1.... 120 columns. Then I have values in A2, B2, C2, .... for 120 columns

I need to compute the following in row 3...

A3=A2*A1, B3=B2*A1+A2*B1, C3=C2*A1+A2*C1+B2*B1......

I want to do this w/o having to edit each cell in row 3

Any help will be appreciated.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
D3 = D2*A1+A2*D1+B2*C1+C2*B1

and

E3 = E2*A1+A2*E1+B2*D1+C2*C1+D2*B1

The entire row three is built this way and I need to do this for 120 columns
 
Upvote 0
That's a messier formula than I want to figure out, but a UDF is simple:

Code:
Function m(r As Range) As Double
    Dim i           As Long
    Dim nCol        As Long
 
    nCol = r.Columns.Count
 
    For i = 1 To nCol \ 2
        m = r(1, i).Value2 * r(2, nCol - i + 1).Value2 + _
            r(2, i).Value2 * r(1, nCol - i + 1).Value2 + m
    Next i
    If nCol Mod 2 = 1 Then m = m + r(1, i).Value2 * r(2, nCol - i + 1).Value2
End Function
There's no error checking.

In A3 and copy across,

=m($A$1:A2)
 
Upvote 0
this is great! It seems to work when the values are in A1, A2, A3, B1, B2, B3... etc I was wondering if this could be tweaked so the rows need not be sequential. Meaning the values in A1:A(x) and B1:B(x) can be separated from each other?
 
Upvote 0
Code:
Function o(rA As Range, rB As Range) As Double
    Dim i           As Long
    Dim nCol        As Long
 
    nCol = rA.Cells.Count
 
    For i = 1 To nCol \ 2
        o = rA(i).Value2 * rB(nCol - i + 1).Value2 + _
            rB(i).Value2 * rA(nCol - i + 1).Value2 + o
    Next i
    If nCol Mod 2 = 1 Then o = o + rA(i).Value2 * rB(nCol - i + 1).Value2
End Function
Still no error checking.
 
Upvote 0
You're welcome, glad it worked for you.
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,866
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top