Hello Everyone,
I currently have a piece of code which I am using to:
1) Use filter from a Pivot Table (Customer names/codes)
2) With Filter applied, a statement is generated on another sheet which needs to be saved as values & formats into a new workbook with the file name taken from cells on the sheet.
From what I know, the loop works generally because I have used it for other functions. However, with this ones, it seems to freeze after saving the first file (when filter is on "All").
I would be grateful if you could help me understand and fix this.
I currently have a piece of code which I am using to:
1) Use filter from a Pivot Table (Customer names/codes)
2) With Filter applied, a statement is generated on another sheet which needs to be saved as values & formats into a new workbook with the file name taken from cells on the sheet.
From what I know, the loop works generally because I have used it for other functions. However, with this ones, it seems to freeze after saving the first file (when filter is on "All").
I would be grateful if you could help me understand and fix this.
VBA Code:
Sub ALoop()
Dim sh As Worksheet
Dim Pt As PivotTable, Pi As PivotItem
Dim xPath As String
Set sh = Worksheets("Data Validation")
xPath = Application.ActiveWorkbook.Path
With sh
Set Pt = .PivotTables(1)
End With
Application.ScreenUpdating = False
Application.DisplayAlerts = False
With Pt.PivotFields("Account")
.ClearAllFilters
.EnableMultiplePageItems = False
For Each Pi In .PivotItems
If Pi.Name <> "(All)" Then
'Call SveShts
Worksheets("STATEMENT OF ACCOUNT").Copy
With Worksheets("STATEMENT OF ACCOUNT").UsedRange
.Copy
.PasteSpecial xlValues
.PasteSpecial xlFormats
End With
Application.CutCopyMode = False
Application.ActiveWorkbook.SaveAs filename:=xPath & "\" & Range("B6").Value & " " & Format(Now(), "DD-MMM-YYYY") & ".xlsx"
Application.ActiveWorkbook.Close False
End If
Next
End With
MsgBox "Everything Complete"
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub