500,000行的Excel“溢出”错误

我有一个500,000行的Excel表。 它有三列,格式如下

Staff Locations Roles 1 Location1 Role1 1 Location2 Role1 2 Location2 Role2 3 Location3 Role3 3 Location3 Role4 

输出格式如下

  Staff Locations Roles 1 Location1, Location2 Role1 2 Location2 Role2 3 Location3 Role3 3 Location3 Role4 

我有下面的VBScript我正在使用的作品,如果行数很less。

 Sub Sort_Duplicates() Dim lngRow, lngRow2 As Long With ActiveSheet Dim flag As Integer: flag = 0 Dim i As Integer Dim columnToMatch As Integer: columnToMatch = 1 Dim column2ToMatch As Integer: column2ToMatch = 3 Dim columnToConcatenate As Integer: columnToConcatenate = 2 lngRow = .Cells(538537, columnToMatch).End(xlUp).Row .Cells(columnToMatch).CurrentRegion.Sort key1:=.Cells(columnToMatch), Header:=xlYes Do If .Cells(lngRow, columnToMatch) = .Cells(lngRow - 1, columnToMatch) Then 'flag = 1 i = 1 lngRow2 = lngRow Do While Cells(lngRow2, columnToMatch) = .Cells(lngRow2 - i, columnToMatch) If .Cells(lngRow2, column2ToMatch) = .Cells(lngRow2 - i, column2ToMatch) Then .Cells(lngRow2, columnToConcatenate) = .Cells(lngRow2, columnToConcatenate) & ", " & .Cells(lngRow2 - i, columnToConcatenate) .Rows(lngRow2 - i).Delete End If i = i + 1 Loop lngRow2 = lngRow2 - 1 End If ' If flag = 1 Then ' lngRow = lngRow2 ' flag = 0 ' Else lngRow = lngRow - 1 'End If Loop Until lngRow = 1 End With End Sub 

当我尝试使用500,000行的工作表时,它开始sorting,但是会抛出一个popup错误“溢出”,而没有附加的消息。 我试图做到这一点与9万,仍然是一样的。 任何build议如何解决这个问题?

提前致谢

首先将所有 Integervariables的Dim更改为Long