Hi Guys, i am new here as well as in setting up macros in excel vba .
I have recorded the MACRO for my massive excel file pivot tables. i have recorded 3 macros for 3 work sheets ( please guide if i can set one macro for all 3 sheets, that excel work book got 6 sheet)
I need help to record this in a better way as my source file changes every day in a perticular folder and i have to change the name in macro every day ...is there anyway i can automise this ?
I have to activate ( open ) the source file to run the macro ..is there any way i can get result when file is closed and have results in new excel work book ?
I am really sorry if i sound bit confuse here ...thanks in advance whoever can help...
Gaurang Patel
PLEASE SEE THE DETAILS BELOW for 3 MACROS which i've created
Sub Macro1()
'
' Macro1 Macro
'
'
Windows("BOOK1.xlsx").Activate
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Brand")
.Orientation = xlPageField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Style code")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Colour-Fit")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("Total qty"), "Sum of Total qty", xlSum
ActiveSheet.PivotTables("PivotTable1").PivotFields("Style code").Subtotals = _
Array(False, False, False, False, False, False, False, False, False, False, False, False)
Windows("TRIAL MACRO FOR TARGET STOCK").Activate
End Sub
Sub Macro2()
'
' Macro2 Macro
'
'
Windows("BOOK1.xlsx").Activate
ActiveWindow.SmallScroll Down:=-9
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Brand")
.Orientation = xlPageField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Quoted seasons")
.Orientation = xlPageField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Style")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Style name")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Colour")
.Orientation = xlRowField
.Position = 3
End With
ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("Protected Stock in Stock qty (before)"), _
"Sum of Protected Stock in Stock qty (before)", xlSum
ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("Protected Stock in Stock qty (after)"), _
"Sum of Protected Stock in Stock qty (after)", xlSum
With ActiveSheet.PivotTables("PivotTable2").DataPivotField
.Orientation = xlColumnField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("Available to sell (before)"), _
"Sum of Available to sell (before)", xlSum
ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("Available to sell (after)"), _
"Sum of Available to sell (after)", xlSum
ActiveSheet.PivotTables("PivotTable2").PivotFields("Colour").Subtotals = Array( _
False, False, False, False, False, False, False, False, False, False, False, False)
ActiveSheet.PivotTables("PivotTable2").PivotFields("Style name").Subtotals = _
Array(False, False, False, False, False, False, False, False, False, False, False, False)
ActiveSheet.PivotTables("PivotTable2").PivotFields("Style").Subtotals = Array( _
False, False, False, False, False, False, False, False, False, False, False, False)
Range("D5").Select
ActiveSheet.PivotTables("PivotTable2").DataPivotField.PivotItems( _
"Sum of Protected Stock in Stock qty (before)").Caption = "DC BEFORE"
Range("D9").Select
Columns("D:G").ColumnWidth = 16.43
Range("E5").Select
ActiveSheet.PivotTables("PivotTable2").DataPivotField.PivotItems( _
"Sum of Protected Stock in Stock qty (after)").Caption = "DC AFTER"
Range("E8").Select
Range("F5").Select
ActiveSheet.PivotTables("PivotTable2").DataPivotField.PivotItems( _
"Sum of Available to sell (before)").Caption = "ATS BEFORE"
Range("F8").Select
ActiveSheet.PivotTables("PivotTable2").PivotSelect _
"'Sum of Available to sell (after)'", xlDataAndLabel, True
Range("G5").Select
ActiveSheet.PivotTables("PivotTable2").DataPivotField.PivotItems( _
"Sum of Available to sell (after)").Caption = "ATS AFTER"
Range("G3").Select
Range("G8").Select
ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("Store sales last 6 months"), _
"Sum of Store sales last 6 months", xlSum
Range("H8").Select
Windows("TRIAL MACRO FOR TARGET STOCK").Activate
End Sub
Sub Macro3()
'
' Macro3 Macro
'
'
Windows("BOOK1.xlsx").Activate
ActiveWindow.SmallScroll Down:=-12
With ActiveSheet.PivotTables("PivotTable3").PivotFields("Brand")
.Orientation = xlPageField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable3").PivotFields("Style")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable3").PivotFields("Style name")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("PivotTable3").PivotFields("Colour")
.Orientation = xlRowField
.Position = 3
End With
With ActiveSheet.PivotTables("PivotTable3").PivotFields( _
"Target stock quoted season")
.Orientation = xlPageField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
"PivotTable3").PivotFields("Positive store stock"), _
"Sum of Positive store stock", xlSum
ActiveSheet.PivotTables("PivotTable3").PivotFields("Colour").Subtotals = Array( _
False, False, False, False, False, False, False, False, False, False, False, False)
ActiveSheet.PivotTables("PivotTable3").PivotFields("Style name").Subtotals = _
Array(False, False, False, False, False, False, False, False, False, False, False, False)
ActiveSheet.PivotTables("PivotTable3").PivotFields("Style").Subtotals = Array( _
False, False, False, False, False, False, False, False, False, False, False, False)
Range("C8").Select
ActiveWindow.SmallScroll Down:=-12
Windows("TRIAL MACRO FOR TARGET STOCK").Activate
End Sub
Display More