最好的方法是将电话号码复制到新工作表中,删除重复项然后从这些值中计数,就像这样
Sub countTel()
Dim rng_list As Range
Dim frow As Long
Dim frow2 As Long
Dim ws As Worksheet
Dim ws2 As Worksheet
Dim sheetName As String
Set ws = ActiveSheet ''change this to sheet with your data in
sheetName = ws.Name
frow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row ''finds number of rows
Set rng_list = ws.Range("d2:d" & frow) ''creates list of tel numbers
Set ws2 = ActiveWorkbook.Sheets.Add(After:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count))
rng_list.Copy Destination:=ws2.Range("A1:A" & frow) ''copys to new sheet
ws2.Range("a1:a" & frow - 1).RemoveDuplicates Columns:=1, Header:=xlNo ''removes duplicates so one of each value
frow2 = ws2.Cells(ws2.Rows.Count, 1).End(xlUp).Row ''finds number of rows
ws2.Range("b1").Formula = "=COUNTIF(" & sheetName & "!$D$2:$D$" & frow & ",A1)" ''adds formula
ws2.Range("b1:b" & frow2).FillDown ''''adds formula to all rows
End Sub
根据您的数据,您可能必须更改列和开始行。
此外,如果您想保存它,您将必须转换为 xlsx,因为 csv 只允许 1 张