Have a formula consider only visible rows

tk19

New Member
Joined
Mar 5, 2002
Messages
33
I have a formula, something like

=COUNTIF(A1:A100,1)

Which will count all cells equal to 1. Is there a way I can have it only count the visible (i.e., its row is not hidden) cells that are equal to 1?


I actually had another question, whether I can do conditional formatting that will either hide a row or change its row height based on the value of a particular cell in that row. I'm guessing that the only way I can do that is through a macro in the Workbook_Change() event.
 
Further explanation is in order. I have two worksheets. Worksheet1 contains the data. The table range is A2:CH5. Row 2 contains the headers and rows 3 thur 5 contains the data. Table name is Table1. Worksheet2 contains a summary of the data. In cell H2 on sheet2 I want to show the average of the visible rows for field3 if the value of field5 for each visible row is equal to 18. The formula that I am using in cell H2 of sheet2 is =Averageif(vis(Table1[Field5]),18,vis(Table1[Field3])). If I remove the vis functyion from the equation I always the the average of all three rows. If I filter out (hide) a row I want the average to only reflect the other two rows (the visible rows). The vis function is the one that I got from this thread.

Hope this clears things up and thanks in advance for your interst and willingness to help.
I never use that structured referencing.

See if you can translate this formula to the structured reference style.

Let's assume this is your data:

Book1
ABC
5RegionAgeAmount
6West2589
7North2310
8South183
9North185
10South2398
11South2133
12East1843
13North1838
14East1929
15North222
16West2399
17East1814
18South1829
19South2370
20South1861
21West1859
22North1884
Sheet1

You want to get the average of Amount when Age = 18.

A2 = 18

Array entered**:

=AVERAGE(IF(SUBTOTAL(2,OFFSET(C6,ROW(C6:C22)-ROW(C6),0,1)),IF(B6:B22=A2,C6:C22)))

** array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.

If you were to filter on Region by North:

Book1
ABC
5RegionAgeAmount
7North2310
9North185
13North1838
15North222
22North1884
Sheet1

The formula result will be 42.3.
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi, could anyone possibly create the code for me for a visible-only COUNTA function, like you did for COUNTIF?

Thanks very much :)
 
Upvote 0
Thanks, but the COUNTA was actually part of a CONCATENATE (which used to work fine w/o filters, but would not react to rows being hidden by a filter), and now that it has been replaced by a CONCATENATE including a SUBTOTAL, the cell just displays the formula written out, instead of the result of the formula.
 
Upvote 0
Thanks, but the COUNTA was actually part of a CONCATENATE (which used to work fine w/o filters, but would not react to rows being hidden by a filter), and now that it has been replaced by a CONCATENATE including a SUBTOTAL, the cell just displays the formula written out, instead of the result of the formula.
If the cell displays the formula maybe the cell is formatted as text?

Change the cell format to General then re-enter the formula.
 
Upvote 0
The easiest way to count ONLY cells that are NOT hidden by a filter is this: =subtotal(103,A1:A100,1)

If you use =subtotal(3,A1:A100,1) it will count both visible AND hidden rows.

Look in HELP - Subtotal function sytax - function number. Cool things hidden there...SUM, MAX, MIN, PRODUCT, COUNT, COUNTA... And you can adapt to having only filtered data in a range considered...or all data in a range considered!
 
Upvote 0

Forum statistics

Threads
1,216,466
Messages
6,130,795
Members
449,593
Latest member
morpheous

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