我有一张包含电话号码和一堆不需要的文字的CSV表格。
如何浏览工作表并显示每个电话号码及其在列表中出现的次数?
例如:
241-342-3242
345-412-4123
543-234-4322
345-412-4123
预期结果:
Number | Occurs
241-342-3242 | 1
345-412-4123 | 2
543-234-4322 | 1
修改
实际文本的格式如下:
2 | 02/01 | 02:25 PM | 555.123.4567 | INCOMING | DT | 5 | 0.00
3 | 02/01 | 12:58 PM | 559.765.4321 | FRESNO | DT | 4 | 0.00
答案 0 :(得分:0)
COUNTIF会这样做。
如果您认为我们正在搜索A2列:A100包含电话号码,请将其放入B2并填写:
=COUNTIF($A$2:$A$100,$B2)
答案 1 :(得分:0)
the best way would be to copy the tel numbers to a new sheet, remove duplicates then count from these values, something like this
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
depending on your data you might have to change columns and start rows.
Also if yo want to save this you will have to convert to xlsx as csv only allow 1 sheet