Hello All
I have recorded a macro to create a pivot table. I thought I had it so that it would create the pivot from the active worksheet only. But looking at the code, it is picking up the sheet name from the one I recorded it from
Can anyone please advise what this would need to be changed to, to achieve this?
Thanks
I have recorded a macro to create a pivot table. I thought I had it so that it would create the pivot from the active worksheet only. But looking at the code, it is picking up the sheet name from the one I recorded it from
Code:
Sub SalPiv()
'
' SalPiv Macro
' Macro recorded 20/06/2012 by imccormick
'
'
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
[COLOR=#ff0000]"'Salary Data'[/COLOR]!R1C2:R50000C17").CreatePivotTable TableDestination:="", _
TableName:="PivotTable12", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable12").DisplayNullString = False
ActiveSheet.PivotTables("PivotTable12").PivotFields("Posting period"). _
Subtotals = Array(False, False, False, False, False, False, False, False, False, False, _
False, False)
ActiveSheet.PivotTables("PivotTable12").PivotFields("Pers.No.").Subtotals = _
Array(False, False, False, False, False, False, False, False, False, False, False, False)
ActiveSheet.PivotTables("PivotTable12").PivotFields("Employee/Appl.Name"). _
Subtotals = Array(False, False, False, False, False, False, False, False, False, False, _
False, False)
ActiveSheet.PivotTables("PivotTable12").AddFields RowFields:=Array("Pers.No." _
, "Employee/Appl.Name"), ColumnFields:="Posting period"
With ActiveSheet.PivotTables("PivotTable12").PivotFields(" Amount")
.Orientation = xlDataField
.Caption = "Sum of Amount"
.Function = xlSum
End With
End Sub
Can anyone please advise what this would need to be changed to, to achieve this?
Thanks