COUNTIF崩溃Excel

我有一个Excel工作表,date和电子邮件地址列,按datesorting。 我想统计在当前发生之前电子邮件地址在工作表中的次数。 COUNTIF(B $ 1:B1,B2)公式有效,但是当我将其复制到超过50,000条logging时,Excel崩溃。 我总共有20万条logging。

Excel(2010)可以处理另一个解决scheme吗?

这是一个在合理的时间内运行的VBA子版本

Sub countPrior() Dim dic As Object Dim i As Long Dim dat As Variant Dim dat2 As Variant ' Get source data range, copy to variant array dat = Cells(1, 2).Resize(Cells(Rows.Count, 1).End(xlUp).Row, 1) ' create array to hold results ReDim dat2(1 To UBound(dat, 1), 1 To 1) ' use Dictionary to hold count values Set dic = CreateObject("scripting.dictionary") ' loop variant array For i = 1 To UBound(dat, 1) If dic.Exists(dat(i, 1)) Then ' return count dat2(i, 1) = dic.Item(dat(i, 1)) ' if value already in array, increment count dic.Item(dat(i, 1)) = dic.Item(dat(i, 1)) + 1 Else ' return count dat2(i, 1) = 0 ' if value not already in array, initialise count dic.Add dat(i, 1), 1 End If Next ' write result to sheet Cells(1, 3).Resize(Cells(Rows.Count, 1).End(xlUp).Row, 1) = dat2 End Sub 

如果macros是你的一个选项,这里是一个macros将为您完成。 我假设你的地址在B列,你希望loggingC列中先前出现的次数,你可以修改它的结构方式。

 Sub countPrior() Application.ScreenUpdating=False bottomRow = Range("B1000000").End(xlUp).Row For i = 2 To bottomRow cellVal = Range("B" & i).Value counter = 0 For j = 1 To i - 1 If Range("B" & j).Value = cellVal Then counter = counter + 1 End If Next j Range("C" & i).Value = counter Next i Application.ScreenUpdating=True End Sub