centsational
New Member
- Joined
- May 28, 2021
- Messages
- 8
- Office Version
- 365
- Platform
- Windows
I have a pivot table, created from an always changing spreadsheet of orders, that I filter by "location". I have code that loops through the filter field to copy the filtered data into 15 other sheets, each sheet named as the current "location" filtered, creating Delivery Order sheets for each location delivery. 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, I'm a somewhat beginner and have been teaching myself just this year.
This is what I have for code:
Any help would be greatly appreciated, I'm a somewhat beginner and have been teaching myself just this year.
This is what I have for code:
VBA Code:
' create the order 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