How to count visible rows and exclude zero?

honkin

Active Member
Joined
Mar 20, 2012
Messages
374
Office Version
  1. 2016
Platform
  1. MacOS
I have some code which counts the number of selections in a column, but I would like it to exclude 0. it uses subtotal 103 so as to only count visible cells

Here is the code

=SUBTOTAL(103,AA16:AA1048561)

So how can I make this formula exclude all 0 in the column? I tried this, but it was not correct =SUBTOTAL(103,AA16:AA1048561,"<>0")

cheers
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
For example

Excel Formula:
=SUBTOTAL(103;A2:A10)-COUNTIF(A2:A10;0)
 
Upvote 0
Try this:-
(You will need to extend the range)

Excel Formula:
=SUMPRODUCT(SUBTOTAL(103,OFFSET(AA16,ROW($AA$16:$AA$23)-ROW($AA$16),0)),--($AA$16:$AA$23<>0))
 
Upvote 0
Solution
For example

Excel Formula:
=SUBTOTAL(103;A2:A10)-COUNTIF(A2:A10;0)
cheers JEC, but that does not seem to work, at least not on a Mac. It generates the standard "there's a problem with this formula" message with the 0 appearing to be highlighted in red
 
Upvote 0
Try this:-
(You will need to extend the range)

Excel Formula:
=SUMPRODUCT(SUBTOTAL(103,OFFSET(AA16,ROW($AA$16:$AA$23)-ROW($AA$16),0)),--($AA$16:$AA$23<>0))
That appears to be perfect, Alex. Just to double check, I hid all the cells in the column which had 0 and the answer matches when it is not filtered, so spot on.

Thanks so much
 
Upvote 0
Ah try to replace the ";" by comma's. I use different region settings
 
Upvote 0
Ah try to replace the ";" by comma's. I use different region settings
ah, looks like 2 ways to skin a cat JEC. Yes, changing to commas worked a treat, with the answer matching that from Alex's code. Unfortunately I cannot choose both as a solution and had already clicked on the tick for Alex's post. I hope you understand, though I very much appreciate both responses.

cheers
 
Upvote 0
@JEC - FYI - the "-COUNTIF(A2:A10;0)" doesn't distinguish between filtered and unfiltered zeroes.
So if there are any zeroes in the hidden rows it will deduct more zeroes that it should.
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,934
Members
449,094
Latest member
teemeren

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