我正在尝试创建一个宏,在选择范围后,它将告诉我在样本中找到多少个20英尺或40英尺的容器。
宏基本上查找字符串“1x20”或“1x40”,当找到任何一个时,变量cont20或cont40将增加1。
我有的代码:
Sub containercount()
Dim count20 As Integer
Dim count40 As Integer
count20 = 0
count40 = 0
For Each cell In Selection
If Not ActiveCell.Find("1x20", LookAt:=xlPart, MatchCase:=False) Is Nothing Then
count20 = count20 + 1
End If
If Not ActiveCell.Find("1x40", LookAt:=xlPart, MatchCase:=False) Is Nothing Then
count40 = count40 + 1
End If
Next cell
MsgBox ("Number of 20ft containers: " & count20 & vbNewLine & "Number of 40ft containers: " & count40)
End Sub
但结果总是零......我将非常感谢你的帮助。
CountIf