-1

我有一个带有电话号码和一堆不需要的文本的 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
4

2 回答 2

0

COUNTIF 将执行此操作。

如果您假设我们正在搜索 A2:A100 列包含电话号码,只需将其放在 B2 中并填写:

=COUNTIF($A$2:$A$100,$B2)
于 2018-02-02T20:45:22.830 回答
0

最好的方法是将电话号码复制到新工作表中,删除重复项然后从这些值中计数,就像这样

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 张

于 2018-02-03T11:25:11.567 回答