Hello,

I'm currently working on a macro that will loop through my sheets and create pivot tables for each sheet. I have the pivot macros down now I'm having trouble getting it to work across all sheets dynamically. The below code works for one sheet that I pre-defined.
How would I create the Pivot table so that it would be dynamic. I want the macro to create the source data based off the worksheet that it's pulling from. Also i want the destination sheet to be named the same as the source sheet, except to add pivot at the end. so sheet 1 would also have sheet 1 pivot that would contain the pivot table.
Basically how do I write the code so that the yellow sections are set to be dynamic and based off the sheet that it is creating the pivot table from?

If i have a loop
Sub macro()
Dim ws As Worksheet
For Each ws In Worksheets

Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
        ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "ALUGA!R1C1:R1048576C27", Version:=xlPivotTableVersion15).CreatePivotTable _
        TableDestination:="'ALUGA Pivot'!R1C1", TableName:="PivotTable1", _
        DefaultVersion:=xlPivotTableVersion15

Next ws

    End Sub