매크로를 기록한 후 이 VBA 코드를 편집하는 데 문제가 있습니다. 매크로 코드는 아래와 같습니다. "wsSplitBU.Copy After:=Aname.Sheets(1)" 줄에 잘못된 한정자가 있다는 오류가 표시됩니다.
여기서 아이디어는 이 4개의 시트를 완전히 새로운 통합 문서에 복제한 다음 저장하기 전에 값으로 붙여넣는 것입니다.
여기 전문가가 코드를 보다 유연하게 편집하는 데 도움을 줄 수 있습니까?
감사합니다!
Sub Data_Cleanser()
Application.ScreenUpdating = False
Dim wsRaw As Worksheet
Set wsRaw = Sheets("RAW DATA")
Dim wsPivot As Worksheet
Set wsPivot = Sheets("Pivot_RAW_DATA")
Dim wsPivotM As Worksheet
Set wsPivotM = Sheets("Pivot")
Dim lastRowRD As Long
lastRowRD = wsRaw.Cells(Rows.Count, "A").End(xlUp).Row
Dim wbS As Workbook
Set wbS = Workbooks("Spend automator.xlsm")
Dim wsSplitBU As Worksheet
Set wsSplitBU = Sheets("Split BU (HUTAS)")
Dim wsLocalS As Worksheet
Set wsLocalS = Sheets("Localization Spend")
Dim wsPlantSp As Worksheet
Set wsPlantSp = Sheets("Bedok, Changi, Bandung Spend")
''''''''''''''''''''''''''''''
'Populate formula'
''''''''''''''''''''''''''''''
[Aa1].Resize(lastRowRD - 1, 1).FormulaR1C1 = ("BU Correction Generator")
[Aa2].Resize(lastRowRD - 1, 1).Formula = ("=VLOOKUP(N2,'BU CORRECTOR REFERENCE'!$A:$C,3,FALSE)")
''''''''''''''''''''''''''''''
'Refresh Pivot'
''''''''''''''''''''''''''''''
wsPivot.Select
ActiveSheet.PivotTables("PivotTable9").PivotCache.Refresh
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh
wsPivotM.Select
ActiveSheet.PivotTables("PivotTable3").PivotCache.Refresh
Dim Aname As String
Aname = ActiveWorkbook.Sheets(1).Range("A1").Value
Workbooks.Add
''''''''''''''''''''''''''''''
'Create new distributable workbook'
''''''''''''''''''''''''''''''
wsPivotM.Copy
wbS.Activate
wsSplitBU.Copy After:=Aname.Sheets(1)
wbS.Activate
wsLocalS.Copy After:=Aname.Sheets(2)
wbS.Activate
wsPlantSp.Copy After:=Aname.Sheets( _
3)
Range("B4:M8").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Localization Spend").Select
Range("B3:M19").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("L1:M1").Select
Application.CutCopyMode = False
Selection.Copy
Range("L2").Select
ActiveSheet.Paste
Sheets("Split BU (HUTAS)").Select
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 3
Range("C18:N46").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("M1:N1").Select
Application.CutCopyMode = False
Selection.Copy
Range("M2").Select
ActiveSheet.Paste
Sheets("Pivot").Select
Application.CutCopyMode = False
ActiveWorkbook.SaveAs Filename:=SpendReport & ".xls"
End Sub
답변1
@akina 예를 들어주실 수 있나요? – Fadhilah Afif 19분 전
이 통합 문서의 시트를 다른 통합 문서 예제로 복사하세요.
Sub copy_sheet()
Workbooks.Open Filename:="c:\tmp\workbook2.xlsx"
ThisWorkbook.Sheets("Sheet1").Copy Before:=Workbooks("workbook2.xlsx").Sheets("Sheet2")
Workbooks("workbook2.xlsx").Save
Workbooks("workbook2.xlsx").Close
End Sub