Multiply 2 columns and then sum the totals VBA

aheverett1

New Member
Joined
May 23, 2017
Messages
16
Hello,

Is there a way to take multiply say A1 * B1, A2 * B2, A3 * B3 then put the extended totals add them together and add those up?

Like this but without using a third column and just putting the total of 196 in a cell?

[TABLE="width: 192"]
<colgroup><col style="width:48pt" width="64" span="3"> </colgroup><tbody>[TR]
[TD="class: xl205, width: 64"]QTY[/TD]
[TD="class: xl205, width: 64"]Price[/TD]
[TD="class: xl205, width: 64"]Ext price[/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]66[/TD]
[TD="align: right"]66[/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]85[/TD]
[TD="align: right"]85[/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[TD="align: right"]15
[/TD]
[TD="align: right"]45[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="class: xl205"]Total
[/TD]
[TD="align: right"]196
[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
try this:



Code:
Sub NoHelper()
    Dim i As Long, lr As Long
    Dim x As Double, y As Double
    lr = Range("A" & Rows.Count).End(xlUp).Row
    x = 0
    For i = 2 To lr
        y = Range("A" & i) * Range("B" & i)
        x = x + y
    Next i
    Range("A" & lr + 1) = "total"
    Range("B" & lr + 1) = x




End Sub
 
Upvote 0
try the following


Excel 2010
AB
1QTYPrice
2166
3185
4315
5Total196
6a
Cell Formulas
RangeFormula
B5=SUMPRODUCT(A2:A4,B2:B4)
 
Upvote 0
OK, should have been a little more specific. My first range actually starts B6 and the other range starts at I6

Thought this would fix it, but it did not.

Private Sub CommandButton1_Click()
Dim i As Long, lr As Long
Dim x As Double, y As Double
lr = Range("B6" & Rows.Count).End(xlUp).Row
x = 0
For i = 2 To lr
y = Range("B6" & i) * Range("I6" & i)
x = x + y
Next i
Range("B6" & lr + 1) = "total"
Range("I6" & lr + 1) = x
End Sub


Also, how would i output the total or the loop into cell "I1"?
 
Upvote 0
Amended Code to fit your better description:

Code:
Option Explicit
Sub Nohelper()
    Dim i As Long, lr As Long
    Dim x As Double, y As Double
    lr = Range("B" & Rows.Count).End(xlUp).Row
    x = 0
    For i = 6 To lr
        y = Range("B" & i) * Range("I" & i)
        x = x + y
    Next i
    Range("I1") = x


End Sub
PLease use code tags when posting VBA
 
Upvote 0

Forum statistics

Threads
1,223,883
Messages
6,175,167
Members
452,615
Latest member
bogeys2birdies

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