當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
我會看看,但檢查這個環節出[避免使用選擇語句] (http://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba-macros) – peege 2014-12-10 23:20:46
你想完成什麼,或者我應該問,「這有效地做什麼?在它停止前有10,000行?「 – peege 2014-12-10 23:26:24
宏從另一個工作表中抓取原始數據,並根據數據中的特定條件將數據格式化爲單獨的選項卡。數據化合物隨着年份的發展而進展,所以這是它第一次停止。我玩了一圈,發現如果我刪除了幾行,以獲得10k行以下的作品,10k或更多,我得到的錯誤,不知道爲什麼。感謝任何洞察 – 2014-12-10 23:44:41