此代碼的想法是從名爲「My list.xlsx
」的工作簿啓動它,並在我的列表的工作表「FX
」上創建一個列表;此列表將基於另一個已打開的工作簿(稱爲「Daily prices.xlsm
」)的電子表格。使用不同工作簿的參考
當我嘗試玩耍時,它似乎不喜歡我在其他工作簿上引用列表來複制它的方式。這裏是我的代碼:
Sub forEachWs()
Dim ws As Worksheet, dest As Worksheet
Dim LastRow As Long
Dim LastRowDestination As Long
Dim ExRateWb As Workbook
Dim DailyPrices As Workbook
Set ExRateWb = ActiveWorkbook
Set DailyPrices = Workbooks("Daily prices.xlsm")
Set dest = Worksheets("FX")
For Each ws In DailyPrices.Worksheets
Select Case ws.Name
Case "FX", "BBG prices", "PRICES"
Case Else
MsgBox DailyPrices.Name
LastRow = ws.UsedRange.Rows.Count
LastRowDestination = dest.UsedRange.Rows.Count + 2
DailyPrices.ws.Range(Cells(1, 1), Cells(LastRow, 5)).Copy
ExRateWb.dest.Cells(LastRowDestination, 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
End Select
Next
End Sub
它在哪一行標記錯誤? – kaybee99