Save As Sheet to two different workbooks one with filters applied

JohnnyPicnic

New Member
Joined
Feb 8, 2021
Messages
17
Office Version
  1. 2019
Platform
  1. Windows
Hello, I would like to save a single sheet from a workbook twice. Once with no filters and once with filer applied.
I can't seem to figure out how to save the first file, close it then move onto the second save as.
This is what I have so far:

VBA Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Application.DisplayAlerts = False


    Dim wb As Workbook
    Set wb = Workbooks.Add
    
    'Save First Work Sheet as xlsx for Google Maps Import
    ThisWorkbook.Sheets("Sites").Copy Before:=wb.Sheets(1)
        If ThisWorkbook.Sheets("Sites").FilterMode Then
        ThisWorkbook.Sheets("Sites").ShowAllData
        End If
    wb.SaveAs "Sites.xlsx", FileFormat:=xlOpenXMLWorkbook
    
    
    
    'Save First Work Sheet with filter as xlsx for Google Maps Import
    
    ThisWorkbook.Sheets("Sites").Copy Before:=wb.Sheets(1)
        If ThisWorkbook.Sheets("Sites").FilterMode Then
        ThisWorkbook.Sheets("Sites").ShowAllData
        End If
    
    wb.Sheets("Sites").Range("$A$1:$Q$121").AutoFilter Field:=14, Criteria1:="<>"
    
    wb.SaveAs "Sites Work Only.xlsx", FileFormat:=xlOpenXMLWorkbook
    
    ActiveWorkbook.Close
    
Application.DisplayAlerts = True
End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Suggestion:
1. Export that worksheet to a new workbook. Save into the desired workbook name.
2. Apply filter to the exported worksheet, SaveAs another workbook name.
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,294
Members
449,077
Latest member
Rkmenon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top