Sumif on special cells

SQUIDD

Well-known Member
Joined
Jan 2, 2009
Messages
2,144
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi All

Hope we are all good.

Im trying to work out if i can sumif on visible cells after a filter.

The info is in a table, if that matters.

The below works really well on counta

VBA Code:
Set RNG1 = Range("B11:B" & Range("B65536").End(xlUp).Row).SpecialCells(xlCellTypeVisible)
R1 = Application.WorksheetFunction.CountA(RNG1)

So Based on that i assumed the below would also work, but no. Have a made a silly mistake, or is it not possible. Should i take a different approach?

VBA Code:
Set RNG2 = Range("H11:H" & Range("H65536").End(xlUp).Row).SpecialCells(xlCellTypeVisible)
R2 = Application.WorksheetFunction.CountIf(RNG2, "1ST")

Thanks for help in advance.

Dave
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try this instead

VBA Code:
Set RNG2 = Range("H11", Range("H" & Rows.Count).End(xlUp))
R2 = Evaluate(Replace("SUMPRODUCT(SUBTOTAL(3,OFFSET(#,ROW(#)-ROW(" & RNG2.Cells(1).Address & "),0,1))*(#=""1ST""))", "#", RNG2.Address))
 
Upvote 0
Solution
Hi Peter.

That workes absolutly spot on, thanks very much for your help.

Now im not sure if you could help me again, since the approach has changed completly, im not sure how to do the last bit.

Maybe i should start a new post, but it seems close to the 1st question.

I will ask either way, and if a new post, let me know. thankyou very much again.

VBA Code:
LR = Range("A" & Rows.Count).End(xlUp).Row
Application.WorksheetFunction.SumIf(Range("H11:H" & LR), "1ST", Range("I11:I" & LR))

Where i want to just sum the visible clls again.

Dave
 
Upvote 0
Assuming dSUM is the variable to hold the sum, try these two changes

Rich (BB code):
Set RNG2 = Range("H11", Range("H" & Rows.Count).End(xlUp))
dSUM = Evaluate(Replace("SUMPRODUCT(SUBTOTAL(9,OFFSET(#,ROW(#)-ROW(" & RNG2.Cells(1).Address & "),1,1))*(#=""1ST""))", "#", RNG2.Address))

The 9 tells SUBTOTAL to SUM rather than COUNTA
The 1 indicates that the column to sum is offset 1 column to the right of the "1ST" column. That is, sum column I because the "1ST" column is H.
 
Upvote 0
Peter

Thanks for the explintion on that. I really appriciate that.

And all good, thankyou for your help on this.

Dace
 
Upvote 0

Forum statistics

Threads
1,225,897
Messages
6,187,703
Members
453,435
Latest member
U4US

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