我有一个excel集,我需要根据名字来计数条目。它们都在同一栏中,每个条目中应该有4条。我需要一个公式来计算不以“零售”或“商业”开头的相同条目的单元格数,并且只返回没有4的单元格中的名称。例如,如果我的数据看起来是这样的话:
NAME
Retail - John
Retail - Sue
Kara
Kara
Joe
Joe
Joe
Joe
Commercial
Sarah我想要一个公式来搜索这个列,只返回“Kara-2”和"Sarah - 1“。“零售”和“商业”从一开始就被排除在外,因为"Joe"=4,我不关心这一点。有什么办法可以让我让这个搜索列,它是否返回第一个计数,以满足该标准的C1,下一个到C2,等等,直到我有一列的只是不符合规定的条目?我想要下面这样的输出:
NAME COUNT
Kara 2
Sarah 1 谢谢你的关注,我真的很感激你能提供的任何帮助和建议!
发布于 2013-11-12 20:14:31
如果数据位于A列中,则在运行此宏后,结果表将位于B&C列中:
Sub MAIN()
Dim A As Range, wf As WorksheetFunction
Dim s1 As String, s2 As String
Dim col As Collection
Set A = Intersect(Range("A:A"), ActiveSheet.UsedRange)
Set wf = Application.WorksheetFunction
Set col = MakeColl(A)
s1 = "Retail"
s2 = "Commercial"
K = 1
For i = 1 To col.Count
v = col.Item(i)
If InStr(v, s1) = 0 And InStr(v, s2) = 0 Then
n = wf.CountIf(A, v)
If n <> 4 Then
Cells(K, "B").Value = v
Cells(K, "C").Value = n
K = K + 1
End If
End If
Next i
End Sub
Public Function MakeColl(rng As Range) As Collection
Set MakeColl = New Collection
Dim r As Range
On Error Resume Next
For Each r In rng
v = r.Value
If v <> "" Then
MakeColl.Add v, CStr(v)
End If
Next r
MsgBox MakeColl.Count
End Functionhttps://stackoverflow.com/questions/19937360
复制相似问题