How do I complete a countif that dosen't include hiden cells

G

Guest

I have a column of various text answers and I want to count the number of
times they appear, but I also have criteria which hides rows of information
and I want the count when these lines are hiden.
 
G

Guest

Telecom said:
I have a column of various text answers and I want to count the number of
times they appear, but I also have criteria which hides rows of information
and I want the count when these lines are hiden.

hi

Countif will count hidden rows e.g =COUNTIF(D4:D7,"=true") will count then
range including row 6 that has been hidden.

if you wanted to know how many rows are hidden in the worksheet then this
macro will give provide the information.

Sub HiddenRows()
Selection.SpecialCells(xlCellTypeLastCell).Select
lastrow = ActiveCell.Row
range(Cells(1, 1), Cells(lastrow, 1)).Select
For i = 1 To lastrow
If Rows(i).Hidden Then
Hrows = Hrows + 1
End If
Next
Cells(1, 1).Select
x = MsgBox("N Hidden rows" & vbTab & Hrows, vbInformation, "Hidden rows In
Sheet")

End Sub

Regards
Peter
 
G

Guest

Or more interesting is count the visible items only with a UDF

Function CountVis(data As range, Crit As Variant) As Long
Dim c, count As Long
For Each c In data
If c.Rows.Hidden Then

ElseIf Not c.Rows.Hidden And c = Crit Then
count = count + 1
End If
Next
CountVis = count
End Function
 
G

Guest

Thnaks for that.

I was hoping to have a running total at the top of the column. I need to
filter the sheet so some rows will be hidden at times. Is there any way I can
do a subtotal and countif combined?
 
G

Guest

Hi

Have a look at Excell Help on subtotals, type 2 is count including hidden
items while type 102 does not include hidden items. If you have you own
formulas within the data, these are ignored so that double counting is
ignored.
in the subtotal =SUBTOTAL(9,D2:D3), 9 is the type you can change manually to
2 to get a count.

I've, pasted the the list from the Help files below. Hope this helps

Peter
Function_num (includes hidden values) Function_num (ignores hidden values)
Function
1 101 AVERAGE
2 102 COUNT
3 103 COUNTA
4 104 MAX
5 105 MIN
6 106 PRODUCT
7 107 STDEV
8 108 STDEVP
9 109 SUM
10 110 VAR
11 111 VARP
 
G

Guest

Thanks for that but:

I am counting a list of unique text values not numbers so I can't use
subtotal.
 
G

Guest

Hi

Yes you can. Say the text column header is called Type, then choose Type as
the field to change and use count as the function to use.

Regards
Peter
 
G

Guest

This presumes a recent version of Excel, and propagates misleading statments
from Help. SUBTOTAL with 100+ arguments does not ignore hidden cells, it
ignores cells in hidden rows (fortunately that is consistent with the OP's
application). If cells are hidden by hiding columns, they will not be
ignored by SUBTOTAL.

VBA code that can recognize all hidden cells (but are not automatically
recalculated when rows/columns are hidden/unhidden) is discussed at
http://support.microsoft.com/kb/150363

Jerry
 
G

Guest

Hi

I'm always finding out I know even less than I thought, I wrote my own UDF
but I forgot about Columns and did not realise your point.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Average of cells in a column 9
Excel Countif cell has diagonal border 6
Countif with a Range of criteria 8
CountIF 3
CountIf previous cell formula 0
COUNTIF Non Contiguous Cells Q 3
countif criteria sg 7
COUNTIF Function 4

Top