0

I have a macro that creates a pivot table with the data from a sheet titled “IBC”. How do I get the macro to create the pivot table from any sheet, not just the one titled “IBC”

I know this code is specifying that pivot table should use Source data from the table "IBC" but how do I get the pivot table to pull from the table/sheet I'm actively viewing, not just "IBC"?

Application.CutCopyMode = False
    Sheets.Add
    pivotws = ActiveSheet.Name
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="IBC", Version:=7).CreatePivotTable TableDestination:=pivotws & "!R3C1", TableName:="PivotTable3", DefaultVersion:=7
    Sheets(pivotws).Select
    Cells(3, 1).Select
    With ActiveSheet.PivotTables("PivotTable3")

BigBen
  • 46,229
  • 7
  • 24
  • 40
Sophie
  • 1
  • [Avoiding the use of Select](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba) in your code should do the trick – cybernetic.nomad Mar 01 '23 at 15:33

0 Answers0