我正在尝试自动化电子表格,以便将数据从一个工作表传输到多个工作表 ,具体取决于区域。有超过 39,000行,我收到错误"Run-time Error '6': Overflow"
。请任何人都可以帮助我,以下是使用的代码。在ADVNCE中感谢
Sub parse_data()
Dim LR As Long
Dim ws As Worksheet
Dim vcol, i As Integer
Dim icol As Long
Dim myarr As Variant
Dim title As String
Dim titlerow As Integer
vcol = 14
Set ws = Sheets("Sheet1")
LR = ws.Cells(ws.Rows.Count, vcol).End(xlUp).Row
title = "A1:AA1"
titlerow = ws.Range(title).Cells(1).Row
icol = ws.Columns.Count
ws.Cells(1, icol) = "Unique"
For i = 2 To LR
On Error Resume Next
If ws.Cells(i, vcol) <> "" And Application.WorksheetFunction.Match(ws.Cells(i, vcol), ws.Columns(icol), 0) = 0 Then
ws.Cells(ws.Rows.Count, icol).End(xlUp).Offset(1) = ws.Cells(i, vcol)
End If
Next
myarr = Application.WorksheetFunction.Transpose(ws.Columns(icol).SpecialCells(xlCellTypeConstants))
ws.Columns(icol).Clear
For i = 2 To UBound(myarr)
ws.Range(title).AutoFilter field:=vcol, Criteria1:=myarr(i) & ""
If Not Evaluate("=ISREF('" & myarr(i) & "'!A1)") Then
Sheets.Add(after:=Worksheets(Worksheets.Count)).Name = myarr(i) & ""
Else
Sheets(myarr(i) & "").Move after:=Worksheets(Worksheets.Count)
End If
ws.Range("A" & titlerow & ":A" & LR).EntireRow.Copy Sheets(myarr(i) & "").Range("A1")
Sheets(myarr(i) & "").Columns.AutoFit
Next
ws.AutoFilterMode = False
ws.Activate
End Sub
答案 0 :(得分:0)
首先,你的问题应该被标记为VBA而不是VB.NET - 这是一个很大的区别,特别是在涉及数据类型的大小时。
在VBA(和VB6)中,声明为Integer
的变量是一个2字节的有符号整数,意味着值范围为-32,768
到32,767
这意味着只要您尝试将32,768
放入声明为Integer的变量中,就会导致您遇到的溢出错误。
将此数据类型更改为“长”可以解决您的问题,因为它的范围为-2,147,483,648
到2,147,483,647