2014-12-03 56 views
0

我想自動化電子表格將數據從一個錶轉移到多張取決於地區在不同的表中的數據拆分。有超過39000線,我得到一個錯誤的"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

首先,你的問題應該被標記VBA不VB.NET - 這是一個很大的區別尤其是在數據類型的大小有關。

在VBA(和VB6)聲明爲Integer變量爲2個字節意義數值範圍內的有符號整數爲-32,76832,767

這隻要你嘗試把32,768到聲明的變量是指整數就會造成你所遇到的溢出錯誤。

將此數據類型更改爲「長」應解決您的問題,因爲它的範圍爲-2,147,483,6482,147,483,647