FossilAmmonite
New Member
- Joined
- Sep 2, 2021
- Messages
- 1
- Office Version
- 365
- Platform
- Windows
Hey there everyone, long time lurker, but first time where im really scratching my head with this one and the MSDN documentation isnt really giving me much of a lead to work off of here.
So I had someone who created a macro that was taking pivot table data, and creating a bunch of sheets for each individual user. since it was just a recorded macro it was super rudimentary and was missing any form of logic just in case the pivot table rows grew or shrank, so i decided to build out a loop to manage it better.
Pretty much what they get when they run the macro is X amount of sheets created, each with the user filtered(as well as a field), but im getting nowhere when i try to put it in a loop. I am doing something wrong with my pivot table items, as I keep having mismatched objects, but I am just wrapped up with confusion on what its supposed to look like. Frankly, im not too sure how the macro worked in the first place, so im definitely missing something here.
Here is one of the commands in the macro(it would do this down the line of each of the cells in that row). this confirmed works.
Here is my loop im trying to make here(im guessing there are multiple problems, but its breaking on the range i think, but i really dont understand how I get that range to be proper as the pivot item usually seems to just return the name of the field (i.e. the data inside the field and none of the actual cell locations or anything)
So I had someone who created a macro that was taking pivot table data, and creating a bunch of sheets for each individual user. since it was just a recorded macro it was super rudimentary and was missing any form of logic just in case the pivot table rows grew or shrank, so i decided to build out a loop to manage it better.
Pretty much what they get when they run the macro is X amount of sheets created, each with the user filtered(as well as a field), but im getting nowhere when i try to put it in a loop. I am doing something wrong with my pivot table items, as I keep having mismatched objects, but I am just wrapped up with confusion on what its supposed to look like. Frankly, im not too sure how the macro worked in the first place, so im definitely missing something here.
Here is one of the commands in the macro(it would do this down the line of each of the cells in that row). this confirmed works.
VBA Code:
Range("B4").Select
Selection.ShowDetail = True
Cells.Select
Cells.EntireColumn.AutoFit
ActiveSheet.ListObjects("Table3").Range.AutoFilter Field:=5, Criteria1:= _
"Param"
Sheets("Sheet2").Select
Here is my loop im trying to make here(im guessing there are multiple problems, but its breaking on the range i think, but i really dont understand how I get that range to be proper as the pivot item usually seems to just return the name of the field (i.e. the data inside the field and none of the actual cell locations or anything)
VBA Code:
Set pt = ActiveSheet.PivotTables("PivotTable1")
Set pits = pt.PivotFields("Employee Name").PivotItems
For Each pit In pits
Sheets("Sheet2").Select
Range (Cells.PivotCell.PivotItem(pit))
Cells.Select
Cells.EntireColumn.AutoFit
ActiveSheet.ListObjects(CStr(pit)).Range.AutoFilter Field:=5, Criteria1:= _
"Param"
Next pit