VBAstudent1986
New Member
- Joined
- Jan 8, 2020
- Messages
- 16
- Office Version
- 2016
- Platform
- Windows
I would like to copy and paste a worksheet that has pivot tables into a new workbook and save them using a specific name using a logic.
For example, in the sheet that has the pivots, I have a filter that has 250 Dealer Codes. I would like to export (Copy) the sheet after applying the filter and move to the next.
i.e. 1. Apply filter 2. Copy into new sheet 3. Save the file as a new workbook 4. File name should be from a list of dealer codes (List could be from a sheet within the original workbook)
Currently I am using the following code. If someone could help me that would be great. Currently I am getting error in the "SaveAs" line of the code - where I am getting the error.
Sub SplitWorkbook_Venkat()
'Updateby20140612
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim xWs As Worksheet
Dim xWb As Workbook
Dim FolderName As String
Application.ScreenUpdating = False
Set xWb = Application.ThisWorkbook
DateString = Format(Now, "yyyy-mm-dd")
FolderName = xWb.Path & "\" & "Venkat"
'MkDir FolderName
Dim i As Long
i = 2
Do While i <= 280
ActiveSheet.PivotTables("PivotTable3").PivotFields("Dlr Num").ClearAllFilters
ActiveSheet.PivotTables("PivotTable3").PivotFields("Dlr Num").CurrentPage = Sheets("DLRNUM").Cells(i, "A").Value
ActiveSheet.PivotTables("PivotTable4").PivotFields("Dlr Num").ClearAllFilters
ActiveSheet.PivotTables("PivotTable4").PivotFields("Dlr Num").CurrentPage = Sheets("DLRNUM").Cells(i, "A").Value
FPath = "D:\Jan 2020\Lease Loan Report New\Venkat\"
FName = "New_Report" & Sheets("DLRNUM").Cells(i, "A").Value & ".xls"
ThisWorkbook.Sheets("Pivot").SaveAs Filename:=FPath & "\" & FName
Application.ActiveWorkbook.Close False
i = i + 1
Loop
'MsgBox "You can find the files in " & FolderName
Application.ScreenUpdating = True
End Sub
For example, in the sheet that has the pivots, I have a filter that has 250 Dealer Codes. I would like to export (Copy) the sheet after applying the filter and move to the next.
i.e. 1. Apply filter 2. Copy into new sheet 3. Save the file as a new workbook 4. File name should be from a list of dealer codes (List could be from a sheet within the original workbook)
Currently I am using the following code. If someone could help me that would be great. Currently I am getting error in the "SaveAs" line of the code - where I am getting the error.
Sub SplitWorkbook_Venkat()
'Updateby20140612
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim xWs As Worksheet
Dim xWb As Workbook
Dim FolderName As String
Application.ScreenUpdating = False
Set xWb = Application.ThisWorkbook
DateString = Format(Now, "yyyy-mm-dd")
FolderName = xWb.Path & "\" & "Venkat"
'MkDir FolderName
Dim i As Long
i = 2
Do While i <= 280
ActiveSheet.PivotTables("PivotTable3").PivotFields("Dlr Num").ClearAllFilters
ActiveSheet.PivotTables("PivotTable3").PivotFields("Dlr Num").CurrentPage = Sheets("DLRNUM").Cells(i, "A").Value
ActiveSheet.PivotTables("PivotTable4").PivotFields("Dlr Num").ClearAllFilters
ActiveSheet.PivotTables("PivotTable4").PivotFields("Dlr Num").CurrentPage = Sheets("DLRNUM").Cells(i, "A").Value
FPath = "D:\Jan 2020\Lease Loan Report New\Venkat\"
FName = "New_Report" & Sheets("DLRNUM").Cells(i, "A").Value & ".xls"
ThisWorkbook.Sheets("Pivot").SaveAs Filename:=FPath & "\" & FName
Application.ActiveWorkbook.Close False
i = i + 1
Loop
'MsgBox "You can find the files in " & FolderName
Application.ScreenUpdating = True
End Sub