Editting the post for a new code which is giving an "Invalid Qualifier" Error
I am having trouble editing this vba code after recording a macro. The macro code is as per below.
I am now getting an "object not defined" error at this line"Dim SpendReport As Workbook Set SpendReport = ActiveWorkbook.Sheets(1).Range("A1").Value Workbooks.Add"
Highly suspecting is my variable definition thats wrong ?
The idea here is to duplicate these 4 sheets into a whole new workbook and then pasting them as values prior to saving.
Would an expert here be able to help with the editting of the code to make this more flexible?
Thank you!
New editted code with object error:
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 SpendReport As Workbook
Set SpendReport = ActiveWorkbook.Sheets(1).Range("A1").Value
Workbooks.Add
''''''''''''''''''''''''''''''
'Create new distributable workbook'
''''''''''''''''''''''''''''''
wsPivotM.Copy
wbS.Activate
wsSplitBU.Copy After:=SpendReport.Sheets(1)
wbS.Activate
wsLocalS.Copy After:=SpendReport.Sheets(2)
wbS.Activate
wsPlantSp.Copy After:=SpendReport.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