根據您需要的計數是多麼複雜,您可能會更好地使用自定義函數,下面的內容可以擴展到測量一些標準,但因爲它會計算任何包含「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