I have a pivot table that I filter by "location". I then need to copy/paste from that filtered pivot table to a sheet that is named the same name as the current "location" filtered. This works perfectly fine so long as there ends up being more than one row of data. However, when there is only one row of data filtered, the code will copy (seemingly) but when moving to the appropriate location sheet it pastes no data.
Any help would be greatly appreciated.
This is what I have for code:
' create the pickup sheets for the deliveries to each location
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Set pt = ActiveSheet.PivotTables.Item(1)
For Each pf In pt.PageFields
For Each pi In pf.PivotItems
pt.PivotFields(pf.Name).CurrentPage = pi.Name
Range("A5", Range("A5").End(xlDown).End(xlToRight)).Select 'range A5 so headers not included
Selection.Copy
Sheets(pi.Name).Visible = True
Sheets(pi.Name).Select
Range("A" & Rows.Count).End(xlUp).Offset(2).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Sheets("Pickup Lists").Select
Sheets(pi.Name).Visible = False