2014-12-10 81 views
0

當Excel工作表原始數據的行數低於10000行時,當它有10,000行以上時,出現錯誤。任何想法?錯誤指向到mu = Cells(joker, 12)錯誤13:類型不匹配行限制限制?

Columns("A:I").Select 
Selection.ClearContents 
Windows("New Registrations.xls").Activate 
ActiveWindow.WindowState = xlNormal 
Columns("A:I").Select 
Selection.Copy 
Windows("Polk Trend Report CYTD.xlsm").Activate 
Range("A1").Select 
ActiveSheet.Paste 
Selection.Interior.ColorIndex = xlNone 
Selection.Font.ColorIndex = 0 

Sheets("Data").Select 

Dim nz As Long 
Dim joker As Long 
Dim lambda As Long 

nz = Cells(4, 12).Value 

Dim mu As Long 
    For joker = 5 To nz + 4 
    lambda = Cells(joker, 11) 
    mu = Cells(joker, 12) 
     If lambda <> 0 And mu - lambda > 1 Then 
      Range("A" & lambda).Select 
      Selection.Copy 
      Range("A" & lambda + 1 & ":A" & mu - 1).Select 
      ActiveSheet.Paste 
      Else: 
     End If 
Next joker 

Range("N5:O" & nz + 4).Select 
Selection.ClearContents 

Dim iota As Long 
Dim kappa As Long 
iota = 7 
Do While Cells(iota, 2).Value <> "" 
    If Cells(iota, 2) = "UNKNOWN" Then 
     kappa = Application.WorksheetFunction.Match(Cells(iota, 1).Value, Range("J1:J" & nz + 4), 0) 
     Cells(kappa, 14).Value = Cells(iota, 7).Value 
     Cells(kappa, 15).Value = Cells(iota, 5).Value 
     Range("A" & iota & ":I" & iota).Select 
     Selection.Delete Shift:=xlUp 
     iota = iota - 1 
    ElseIf Cells(iota, 2) = "Zone Total" Then 
     Range("A" & iota & ":I" & iota).Select 
     Selection.Delete Shift:=xlUp 
     iota = iota - 1 
    ElseIf Application.WorksheetFunction.And(Cells(iota, 5) = 0, Cells(iota, 7) = 0) Then 
     Range("A" & iota & ":I" & iota).Select 
     Selection.Delete Shift:=xlUp 
     iota = iota - 1 
    Else: 
    End If 
iota = iota + 1 
Loop 

Range("A" & iota & ":I" & iota).Select 
Selection.Delete Shift:=xlUp 

Range("C5:I5").Select 
Selection.Copy 
Range("C6").Select 
ActiveSheet.Paste 

Set pvtTable = Worksheets("Total Dealer (Trend)").Range("O5").PivotTable 
pvtTable.RefreshTable 
Sheets("Total Dealer (Trend)").Select 
Cells.Select 
Selection.Columns.AutoFit 

Sheets("Data").Select 
Range("S40:T" & nz + 39).Select 
Selection.Copy 
Range("A2").Select 
Sheets("Total Dealer (Trend)").Select 
Range("B40").Select 
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ 
    :=False, Transpose:=False 
    Application.CutCopyMode = False 

Sheets("Data").Select 
Range("U40:U" & nz + 39).Select 
Selection.Copy 
Range("A2").Select 
Sheets("Total Dealer (Trend)").Select 
Range("E40").Select 
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ 
    :=False, Transpose:=False 
    Application.CutCopyMode = False 
Range("B40:E" & nz + 39).Select 
Selection.Sort Key1:=Range("E40"), Order1:=xlDescending, Header:=xlNo _ 
    , OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ 
    DataOption1:=xlSortNormal 
Range("A1").Select 
ActiveWindow.WindowState = xlMaximized 

End Sub 
+1

我會看看,但檢查這個環節出[避免使用選擇語句] (http://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba-macros) – peege 2014-12-10 23:20:46

+0

你想完成什麼,或者我應該問,「這有效地做什麼?在它停止前有10,000行?「 – peege 2014-12-10 23:26:24

+0

宏從另一個工作表中抓取原始數據,並根據數據中的特定條件將數據格式化爲單獨的選項卡。數據化合物隨着年份的發展而進展,所以這是它第一次停止。我玩了一圈,發現如果我刪除了幾行,以獲得10k行以下的作品,10k或更多,我得到的錯誤,不知道爲什麼。感謝任何洞察 – 2014-12-10 23:44:41

回答

0

我想你可能有一個格式變化發生在工作表10,000行的後。說這是一個日期,現在是一般或一些其他類型的衝突,你正在爲畝的價值的結果數據不匹配由 「L10000」

設置檢查低於10,000單元格的格式。特別是列「L」

0

這是一個示例錯誤處理程序,希望您可以將它複製並粘貼到代碼中,並在發生錯誤時輸出失敗單元的值,然後您可以更正它。下面的那張就在你的代碼

On Error GoTo MyProcedure_Error 

然後頂部下方上面去年底子

MyProcedure_Exit: 
     On Error GoTo 0 
     Exit Sub 

MyProcedure_Error: 
     Select Case Err.Number 
       'the "Case 9" statement below is left as an example to show how you could code a 
       'specific error message if a specifc module needed it 
       'Case 9 
        'MsgBox "The input file does not appear to be in the correct format, for importing into the " & _ 
        '" Locations tab" & vbCrLf & "The expected format is " & Str(Import_Cols) & " columns, Pipe Delimited" & _ 
        'vbCrLf, vbCritical, "Error in in procedure TrimColumn of Module DeveloperToolKit" 
       Case Else 
       MsgBox "An unexpected error has occured, the call value that has failed is." & _ 
        vbCrLf & Cells(joker, 12) & _ 
        vbCrLf & "Error Code = " & Str$(Err.Number) & _ 
        vbCrLf & "Error Text = " & Err.Description, vbCritical, "Critical Error" 
     End Select 
     Resume MyProcedure_Exit 
+0

運行時錯誤13 – 2014-12-11 01:02:42

+0

類型不匹配的代碼行是mu = Cells(joker,12) – 2014-12-11 01:03:42

+0

好吧,我現在看到爲什麼前面的評論提到了「類型」衝突。您是否嘗試添加錯誤並在錯誤塊中打印出「Cells(joker,12)」?無論是debug.print或MSGBOX細胞(小丑,12) – 2014-12-11 01:07:31