我有以下代码,可根据特定搜索条件获取值的计数:
Sub WBR()
Dim wf As WorksheetFunction
Set wf = Application.WorksheetFunction
With ActiveWorkbook.Worksheets("TT") 'no of tickets processed - summary
[AE43] = wf.CountIfs(.Range("I:I"), "<>Duplicate TT", _
.Range("G:G"), "<>Not Tested", _
.Range("U:U"), "Item")
End With
With ActiveWorkbook.Worksheets("TT") 'not tested tickets - summary
[AE44] = wf.CountIfs(.Range("G:G"), "Not Tested")
End With
With ActiveWorkbook.Worksheets("TT") 'Tickets moved back- outdated OS and App Versions - summary
[AE45] = wf.CountIf(.Range("I:I"), "Outdated App Version") + wf.CountIf(.Range("I:I"), "Outdated OS")
End With
End Sub
现在我需要做一个类似的功能,但不知道该怎么做:
F
和G
中的COMPATIBLE
F
的{{1}}更多,则应在单元格中更新该值COMPATIBLE
有更多计数,则应在同一单元格中更新。如何使用上面的代码执行此操作?
答案 0 :(得分:2)
您可以在现有代码的末尾添加此内容。只需在COMPATIBLE
和F
列中计算G
,并根据您的条件设置[AE46]
的值:
' compare columns F and G compatible counts
Dim lngFCompatibleCount As Long
Dim lngGCompatibleCount As Long
With ActiveWorkbook.Worksheets("TT")
lngFCompatibleCount = wf.CountIf(.Range("F:F"), "COMPATIBLE")
lngGCompatibleCount = wf.CountIf(.Range("G:G"), "COMPATIBLE")
End With
If lngFCompatibleCount > lngGCompatibleCount Then
[AE46] = lngFCompatibleCount
Else 'not sure about condition where count for F= count for G
[AE46] = lngGCompatibleCount
End If