gpt4 book ai didi

vba - VBA 中的比较计数

转载 作者:行者123 更新时间:2023-12-03 03:42:29 25 4
gpt4 key购买 nike

我有以下代码,它将根据特定搜索条件获取值的计数:

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

现在我需要做一个类似的功能,但不知道该怎么做:

  • 检查 FG 列中的 COMPATIBLE 数量
  • 如果 F 具有更多 COMPATIBLE,则应在单元格中更新该值
  • 否则,如果 G 的计数更多,则应在同一单元格中更新。

如何使用上面的代码执行此操作?

最佳答案

您可以将其添加到现有代码的末尾。只需计算 FG 列中 COMPATIBLE 的数量,然后根据您的情况设置 [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

关于vba - VBA 中的比较计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41561905/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com