我正在尝试创建一个宏来计算给定列中的特定值。例如,我想计算 G 列中包含“糖果”的所有单元格的数量。我该怎么做呢?
问问题
2980 次
1 回答
0
怎么样:
Sub dural()
Dim s As String
Dim r As Range
Dim wf As WorksheetFunction
Set wf = Application.WorksheetFunction
s = "candy"
Set r = Range("G:G")
MsgBox wf.CountIf(r, s)
'
' and if you want to count phrases including candy then:
'
s = "*" & s & "*"
MsgBox wf.CountIf(r, s)
End Sub
编辑:
并将结果存储在工作表单元格中:
Sub dural()
Dim s As String
Dim r As Range
Dim wf As WorksheetFunction
Set wf = Application.WorksheetFunction
s = "candy"
Set r = Range("G:G")
s = "*" & s & "*"
[H3] = wf.CountIf(r, s)
End Sub
于 2013-10-26T11:50:56.880 回答