我需要從多個工作表複製單元格B3:W400(每次運行時都會有不同的名稱)並將值粘貼到「CombinedPlans」中,在最後添加每個新選擇。我需要從代碼中排除3張:IBExport,MonthlyIBs和組合計劃。將多個工作表但不是所有工作表的值複製/粘貼到一個工作表中
大量的反覆試驗給了我下面的代碼,我在我的「練習」工作簿中工作。現在,我已將它放入我的製作工作簿中,不再複製任何工作表。它只是直接跳到消息框。我究竟做錯了什麼?
Sub consolidatetest()
Sheets("CombinedPlans").Select
Range("B3:W1048576").Select
Selection.ClearContents
Dim J As Integer
Dim sh As Worksheet
Const excludeSheets As String = "QBExport,MonthlyIBs,CombinedPlans"
On Error Resume Next
For Each sh In ActiveWorkbook.Worksheets
If IsError(Application.Match(sh.Name, Split(excludeSheets, ","))) Then
Application.GoTo Sheets(sh.Name).[b3]
Range("B3:W400").Select
Selection.Copy
Worksheets("CombinedPlans").Activate
Range("B1048576").End(xlUp).Offset(rowOffset:=1, columnOffset:=0).PasteSpecial xlPasteValues
End If
Next
Application.CutCopyMode = False
MsgBox "Complete!"
End Sub
這裏是另一個你可以調查http://www.xlorate.com/vba-examples.html#Loop%20Through%20Folder – Davesexcel