我試圖複製所有工作表,一次一個,並粘貼到新工作表中。這些文件來自多個第三方,因此工作表可能會有所不同。當我試圖確定最後一行Lrow
和最後一列Lcol
時,我遇到了一個問題,因爲出現錯誤的地方是Object doesn't support this property or method
。我打算將這個提交給我的工作,所以任何有關防錯或一般宏提示的幫助表示讚賞。VBA:嘗試將所有工作表合併到一個工作簿中的一個新工作表中
Sub ws_copy()
Dim Lrow As Long
Dim Lcol As Long
Dim Pasterow As Long
Dim WSCount As Integer
Dim i As Integer
'On Error Resume Next
'Application.DisplayAlerts = False
i = Application.InputBox(prompt:="Enter the place order of first tab to be copied.", Title:="Worksheet Consolidation", Type:=1)
If IsEmpty(i) = True Then
Exit Sub
Else
If IsNumeric(i) = False Then
MsgBox "Enter a numeric value."
Else
If IsNumeric(i) = True Then
Worksheets.Add(before:=Sheets(1)).Name = "Upload"
WSCount = Worksheets.Count
For i = i + 1 To WSCount
Lrow = Worksheets(i).Find("*", After:=Cells(1, 1), _
LookIn:=xlFormulas, _
Lookat:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Lcol = Worksheets(i).Find("*", After:=Cells(1, 1), _
LookIn:=xlFormulas, _
Lookat:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Pasterow = Lrow + 1
Workbook.Worksheets(i).Range(Cells(1, 1), Cells(Lrow, Lcol)).Copy
Workbook.Worksheets("Upload").Cells(Pasterow, 1).Paste
Next i
Else
Exit Sub
End If
End If
End If
'On Error GoTo 0
'Application.DisplayAlerts = False
End Sub
我可以不承擔任何一列將有因爲各種文件的最後一個單元格收到 – druwel
的代碼Lrow和Lcol用,說對象不支持這樣的錯誤回來屬性或方法 – druwel
是的,想法是在每次粘貼新的WS時確定「上載」工作表中的最後一行並向下移動一行,以便粘貼可以發生而不會混淆數據。 – druwel