根据您需要的计数是多么复杂,您可能会更好地使用自定义函数,下面的内容可以扩展到测量一些标准,但因为它会计算任何包含“AS TTE”的单元格或“PTY LTD”,但指望每个单元为1:
Public Function CountIfExt(Rng As Range, str1 As String, str2 As String) As Long
Dim c As Range
Dim x As Long
For Each c In Rng
If InStr(c.Value, str1) > 0 Or InStr(c.Value, str2) > 0 Then
x = x + 1
End If
Next c
CountIfExt = x
End Function
改变“或”到“和”会算包含都串细胞,但检查细胞包含都只有一次,即排除那么有'Trang AS TTE PTY LTD AS TTE'的细胞:(重新阅读你的问题,我不认为这是你以后的样子,但是要演示如何扩展这个功能......)
Public Function CountIfExt(Rng As Range, str1 As String, str2 As String) As Long
Dim c As Range
Dim x As Long
Dim lstr1 As Long, lstr2 As Long
For Each c In Rng
lstr1 = InStr(c.Value, str1)
lstr2 = InStr(c.Value, str2)
If lstr1 > 0 And lstr2 > 0 Then
If InStr(lstr1 + 1, c.Value, str1) = 0 _
And InStr(lstr2 + 1, c.Value, str2) = 0 Then
x = x + 1
End If
End If
Next c
CountIfExt = x
End Function
希望这可以让你获得足够的空间来满足你的需求。
@pnuts这是后来添加的,我没有注意到编辑。我会修改我的答案。 – Jerry 2013-05-01 17:43:22