我正在研究VBA程序,该程序假设要对两列中满足特定条件的单元格的数量进行计数,并且它将在单元格A5中显示该值。由于范围已自动过滤。例如,当我过滤范围时,仅显示Y1中“ L”和“ Veg”的订单数量。范围A5应该改变。
虽然程序能够计算出满足两个条件的项目数,但在我过滤结果时不会重新计算。
例如,可以说整个学校总共有5个大蔬菜。如果我将结果过滤为仅显示Year 1,则只有一个订单时,结果仍为5。
Dim i As Long
Dim r As Range
Dim wsCheck As Worksheet
i = 0
Set wsCheck = Worksheets("JIS")
For Each r In Intersect(wsCheck.AutoFilter.Range.Columns(Col_Western), wsCheck.AutoFilter.Range.SpecialCells(xlCellTypeVisible)).Cells
If wsCheck.Cells(r.Row, Col_Starter) = "S" And wsCheck.Cells(r.Row, Col_Dessert) = "WESTERN" Then
i = i + 1
wsCheck.Range("A5") = "S:" & " " & i
End If
Next r
Set wsCheck = Nothing
答案 0 :(得分:0)
使用hidden
属性检查行是否被过滤。
If wsCheck.Cells(r.Row, Col_Starter) = "S" And wsCheck.Cells(r.Row, Col_Dessert) = "WESTERN" And r.EntireRow.Hidden = False Then