Sumif / Countif Visible Cells Only

Evagrius Ponticus

Well-known Member
Joined
May 24, 2007
Messages
1,467
Hello - I've been struggling to get these to work . .I would appreciate any help! I am trying to get these formulas to work for visible cells only. Thank you!


Code:
=COUNTIF(R12:R526,"<0")

Code:
=SUMIF(R12:R526,"<0")
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hello - I've been struggling to get these to work . .I would appreciate any help! I am trying to get these formulas to work for visible cells only. Thank you!


Code:
=COUNTIF(R12:R526,"<0")

Code:
=SUMIF(R12:R526,"<0")

Try...
Code:
=SUMPRODUCT(
   SUBTOTAL(2,OFFSET(R12,ROW(R12:R526)-ROW(R12),,1)),
   --(R12:R526 < 0))
 
=SUMPRODUCT(
   SUBTOTAL(9,OFFSET(R12,ROW(R12:R526)-ROW(R12),,1)),
   --(R12:R526 < 0))
 
Upvote 0
Try,

For COUNTIF,

Code:
=SUMPRODUCT(SUBTOTAL(3,OFFSET(R12:R526,ROW(R12:R526)-ROW(R12),0,1)),--(R12:R526 < 0))

For SUMIF,

Code:
=SUMPRODUCT(SUBTOTAL(3,OFFSET(R12:R526,ROW(R12:R526)-ROW(R12),0,1)),--(R12:R526 < 0),R12:R526)
 
Upvote 0
WOW - this is incredible Aladin and Hazeeb - just brilliant!!!

This resolves my obstacle, but if either of you would care to explain how these formulas work - I would be grateful!! Thanks!
 
Upvote 0
Try...
Code:
=SUMPRODUCT(
   SUBTOTAL(2,OFFSET(R12,ROW(R12:R526)-ROW(R12),,1)),
   --(R12:R526 < 0))
 
=SUMPRODUCT(
   SUBTOTAL(9,OFFSET(R12,ROW(R12:R526)-ROW(R12),,1)),
   --(R12:R526 < 0))

Hello Aladin,

Maybe a silly question but I was just wondering as I was going through this post. Your formulas works great but why should anyone (including myself as i use a lot of your hints) use sumproduct in this specific example since if we just "custom Auto-filter" the list and use Subtotal function it will give us the result that Evagrius was looking for?

Thanx

George
 
Upvote 0
Hello Aladin,

Maybe a silly question but I was just wondering as I was going through this post. Your formulas works great but why should anyone (including myself as i use a lot of your hints) use sumproduct in this specific example since if we just "custom Auto-filter" the list and use Subtotal function it will give us the result that Evagrius was looking for?

Thanx

George

Let A2:F400 house a sample, with headers in A2:F2.

Let F3:F400 house the occurrences FAD, GAD, KAD, LAD, YAD, etc.

Lets (custom) AutoFilter on the A range, also say on the C range.

How would you count the occurrences of GAD in the F range?
 
Upvote 0
Let A2:F400 house a sample, with headers in A2:F2.

Let F3:F400 house the occurrences FAD, GAD, KAD, LAD, YAD, etc.

Lets (custom) AutoFilter on the A range, also say on the C range.

How would you count the occurrences of GAD in the F range?

Hello again Aladin

Late seen your answer late response...

Thanx! I tried it as an example the way you put it. It works great with numbers but when i tried in column F the strings FAD, GAD, LAD etc and I used:

=SUMPRODUCT(SUBTOTAL(2;OFFSET(F3;ROW(F3:F50)-ROW(F3);;1));--(F3:F50="OAD"))

to return the occurrences of OAD i got a zero. Evaluating the formula gave me an array of Os. Where did i go wrong?
 
Upvote 0
Hello again Aladin

Late seen your answer late response...

Thanx! I tried it as an example the way you put it. It works great with numbers but when i tried in column F the strings FAD, GAD, LAD etc and I used:

=SUMPRODUCT(SUBTOTAL(2;OFFSET(F3;ROW(F3:F50)-ROW(F3);;1));--(F3:F50="OAD"))

to return the occurrences of OAD i got a zero. Evaluating the formula gave me an array of Os. Where did i go wrong?

You need to switch from func num 2 [i.e., COUNT] to func num 3 [i.e., COUNTA]... Thus:

=SUMPRODUCT(SUBTOTAL(3;OFFSET(F3;ROW(F3:F50)-ROW(F3);;1));--(F3:F50="OAD"))

for COUNTA counts everything, inculuding text values.
 
Upvote 0
You need to switch from func num 2 [i.e., COUNT] to func num 3 [i.e., COUNTA]... Thus:

=SUMPRODUCT(SUBTOTAL(3;OFFSET(F3;ROW(F3:F50)-ROW(F3);;1));--(F3:F50="OAD"))

for COUNTA counts everything, inculuding text values.


Thanx!!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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