vba to find the sum product of filtered data

abhi_jain80

New Member
Joined
May 31, 2021
Messages
27
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have filtered the data using the below vba code which is filtering the rows if column G is not blank and column F is 0 and column F is blank.

Range("L6") = Application.CountIfs(Columns("G:G"), "<>", Columns("F:F"), "=0") + Application.CountIfs(Columns("G:G"), "<>", Columns("F:F"), "")

The count of rows filtered out is 3 which is fine. Now I need to find the sum product of column G and column H of the filtered data but struggling to get the code, can somebody help me please? Image attached...

Apologies if this has been solved earlier and thanks in advance...

Abhi
 

Attachments

  • sample.PNG
    sample.PNG
    13.6 KB · Views: 26
Let's assume that Sheet1 contains the source data, try...

VBA Code:
    Dim lastRow As Long
    With Worksheets("Sheet1")
        lastRow = .Cells(.Rows.Count, "H").End(xlUp).Row
    End With
   
    With Sheets(2).Range("A10")
        .Formula = "=SUMPRODUCT(--('Sheet1'!F2:F" & lastRow & "=0),--('Sheet1'!G2:G" & lastRow & "<>""""),'Sheet1'!G2:G" & lastRow & ",'Sheet1'!H2:H" & lastRow & ")"
        .Value = .Value
    End With

By the way, just in case you are not aware of it, Sheets(2) refers to your sheet by index number, not by name. If you actually want to refer to your worksheet called "Sheet2", then you would need to refer to it as Worksheets("Sheet2").

Hope this helps!
Great, this helps a lot. Thank you
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,214,834
Messages
6,121,871
Members
449,054
Latest member
juliecooper255

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