Sum Column only if matches criteria

mnoah

Board Regular
Joined
Oct 14, 2015
Messages
54
Hi everyone,
This should be an easy one. I have account numbers in column G, and invoice amounts in column F. I want to
  1. Insert a new row once there is a new account number.
  2. Sub total the invoice amounts in that new row.


InvoiceAccount
$511111
$511111
$1011111
$20Subtotal
$322222
$322222
$322222
$322222
$12Subtotal

<tbody>
</tbody>


I have gotten this far with the code here:
Code:
Sub InsertRowsAtValueChange()Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
Set WorkRng = Worksheets("Billing").Range("G4:G1000")


Application.ScreenUpdating = False
For i = WorkRng.Rows.Count To 2 Step -1
    If WorkRng.Cells(i, 1).Value <> WorkRng.Cells(i - 1, 1).Value Then
        'inserts blank row after new account #
        WorkRng.Cells(i, 1).EntireRow.Insert
        'Inserts text for subtotal
        WorkRng.Cells(i, 1).Value = "Sub total"
        'NEED FORMULA TO Sub Total each account
        WorkRng.Cells(i, 0).Value = Application.SumIf(Range("g4:g1000"), Cells(i, 1), Range("F4:f1000"))
        
    End If
Next
Application.ScreenUpdating = True
End Sub

Any help is appreciated!

Thanks
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
I haven't, but I am looking to do this calculation within another routine. The file is used by non-Excel minded people and it's part of an email notification system.
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,834
Members
449,192
Latest member
mcgeeaudrey

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