这段代码计算了E列中的空白单元格,所以逻辑是正确的。但是,在计算空白单元格之前,我想从H列中排除“Cash”。
该代码确实对列H(不包括现金)应用了过滤器,但是对于包括现金的数据,空白单元格也会被计入。
Sub exampleTHis()
ActiveSheet.Range("H:H").AutoFilter Field:=8, Criteria1:="<>Cash", _
Operator:=xlAnd
Dim ws As Worksheet, testRange As Range, aCount As Long, zAnswer
For Each ws In ThisWorkbook.Worksheets
Set testRange = Intersect(ws.Range("E:E"), ws.UsedRange)
'Set testRange = ws.Range("E2", Range("E" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible)
If Not testRange Is Nothing Then
aCount = Application.WorksheetFunction.CountBlank(testRange)
If aCount > 0 Then
'blank cells found....
zAnswer = MsgBox(aCount & " blank values found in at " & ws.Name & testRange.Address & ". Continue macro?", vbYesNo)
If zAnswer = vbNo Then Exit For
End If
End If
Next ws
End Sub
1条答案
按热度按时间wfauudbj1#
使用
AutoFilter
和SpecialCells
对自动过滤微柱中的空白进行计数如果没有空白单元格则继续