無論我做什麼,我都無法讓這個錯誤消失。這個當前版本的代碼是爲了完整地說明每個引用。 「BOM組件的設置範圍」行後出現錯誤。大多數主題指出,使用.Range(Cells())而不指定單元格的位置將導致此錯誤,但我已經完成了完整的矯枉過正的引用,因此我不確定它爲什麼仍然出錯。這裏也只有一個工作簿。VBA錯誤1004設置範圍相等
@Scott Craner @BruceWayne我終於明白了; Oracle報告以一種非常漂亮的格式出現,並且循環中的第一張表格導致範圍實際上不相等。一旦我刪除了它,它就完美地運行了。
Sub Macro3()
'
' Macro3 Macro
'
' Keyboard Shortcut: Ctrl+c
'
Dim ws As Worksheet
Dim lastRow As Integer
Dim summaryRow As Integer
Dim currentSheetRows As Integer
Dim i As Integer
Dim j As Integer
summaryRow = 2
For Each ws In ActiveWorkbook.Worksheets
If ws.Range("L3") = "" Then
currentSheetRows = ws.Cells(ws.Rows.Count, "F").End(xlUp).Row
i = summaryRow
j = summaryRow
'set range for item # and item UOM'
For j = summaryRow To (summaryRow + (currentSheetRows - 3))
Sheets("Summary").Cells(j, 1).Value = ws.Cells(2, 1).Value
Next j
For i = summaryRow To (summaryRow + (currentSheetRows - 3))
Sheets("Summary").Cells(i, 2).Value = ws.Cells(2, 1).Value
Next i
'set range for BOM components'
ThisWorkbook.Worksheets("Summary").Range(ThisWorkbook.Worksheets("Summary").Cells(summaryRow, 3), ThisWorkbook.Worksheets("Summary").Cells((summaryRow + (currentSheetRows - 3)), 6)).Value = ThisWorkbook.Worksheets(ws.Name).Range(ThisWorkbook.Worksheets(ws.Name).Cells(3, 6), ThisWorkbook.Worksheets(ws.Name).Cells(currentSheetRows, 9)).Value
summaryRow = summaryRow + currentSheetRows
End If
Next ws
End Sub
「Set ...」語句中的那些「.Values」不應該被刪除嗎? – user3598756
@ user3598756 - 哦,你說的沒錯。我已更新該帖子。 – BruceWayne
不會upvoting這個,直到你的代表改變從'6666' = P(通過XD提醒我) – findwindow