Hi Guys,
Im new here, hope you can help (I heard you can) :).
So I have this code here, it works really well, retrieves data from pivot table, renames sheets etc. Problem is that each time I have more/less rows in the pivot, I have to amend it accordingly. How can i make it dynamic just so it recognises how many rows there are in the pivot and does its magic for all staff ID’s (rows)?
thanks
Jacek
Sub drill()
Dim sel As Variant
Application.ScreenUpdating = False
Sheets(“Pivot”).Activate
With Sheets(“Pivot”).PivotTables(1)
sel = .GetPivotData(“Count of Patient ID”, “Staff ID”, Range(“a9”).Value)
sel = .GetPivotData(“Count of Patient ID”, “Staff ID”, Range(“a9”).Value).Address
Range(sel).ShowDetail = True
Range(“a1”).Select
End With
NewName = Range(“B2”).Value
ActiveSheet.Name = NewName
Sheets(“Pivot”).Activate
With Sheets(“Pivot”).PivotTables(1)
sel = .GetPivotData(“Count of Patient ID”, “Staff ID”, Range(“a10”).Value)
sel = .GetPivotData(“Count of Patient ID”, “Staff ID”, Range(“a10”).Value).Address
Range(sel).ShowDetail = True
Range(“a1”).Select
End With
Application.ScreenUpdating = True
End Sub