2014-02-19 8 views
0

하이라이트되고 표시되는 (숨겨지지 않은) 모든 행 수를 계산하려고합니다. 내 수식이 작동하지만 숨겨진 행이 여전히 숨겨져 있습니다. 강조 표시되고 보이는 행만 어떻게 계산합니까?VBA : 범위에서 숨겨진 행을 무시하는 방법?

'This function will count how many cells in a given range for a given color and are visible 

Function COUNTCELLCOLORSIF(CellRange As Range) As Long 

Dim rngCell 

Application.Volatile 

For Each rngCell In CellRange 
    If rngCell.Interior.ColorIndex = "36" and rngCell.visible Then 
     COUNTCELLCOLORSIF = COUNTCELLCOLORSIF + 1 
    End If 
Next rngCell 

End Function 
+4

확인'rngCell.RowHeight'는 셀> 0 –

+0

@simoco 내가, 내가 formla을 계산할입니다 "= COUNTCELLCOLORSIF (A1 : A10)" – thedeepfield

+0

@TimWilliams, 트릭을 해 줘서 고마워! – thedeepfield

답변

1

를 사용하여이 같은 시도 specialcells(xlcelltypevisible)

Function COUNTCELLCOLORSIF(CellRange As Range) As Long 

Dim rngCell 

Application.Volatile 

For Each rngCell In CellRange.specialcells(xlcelltypevisible) 
    If rngCell.Interior.ColorIndex = "36" Then 
     COUNTCELLCOLORSIF = COUNTCELLCOLORSIF + 1 
    End If 
Next rngCell 

End Function 
1

:

Function COUNTCELLCOLORSIF(CellRange As Range) As Long 
Dim rngCell, visibleCells 

Application.Volatile 
visibleCells = CellRange.SpecialCells(xlCellTypeVisible) 

For Each rngCell In visibleCells 
    If rngCell.Interior.ColorIndex = "36" and rngCell.visible Then 
     COUNTCELLCOLORSIF = COUNTCELLCOLORSIF + 1 
    End If 
Next rngCell 

End Function 
관련 문제