Hi Guys,

Got a bit of a complicated one (considering I am pants with VBA). Below is my code I have so far.
I'm attempting to click a macro button that would then run and
  1. Create a folder based on a cell (S6)
  2. Filter the pivot table based on the input (This bit works fine)
  3. Save a new file named based on a cell (S5) within the folder created
  4. Filter the pivot table to new criteria (Again, works fine)
  5. Save new file based on cell (s5) within folder created
  6. Repeat with all pivot criteria....

Sorry my code is a massive mess, I picked up the folder creation and saving VBA from the internet and have been trying to play around with it but to no avail

Any help massively appreciated


Sub Save()

Dim strFilename, strDirname, strPathname, strDefpath As String
On Error Resume Next ' If directory exist goto next line

strDirname = Range("s6").Value ' New directory name

strFilename = Range("s5").Value 'New file name
strDefpath = "\\Gwukbhxfs01\public\Ocean Product\Ocean Statistics and Reports\Branch Reports" 'Default path name
If IsEmpty(strDirname) Then Exit Sub
If IsEmpty(strFilename) Then Exit Sub

MkDir strDefpath & strDirname
strPathname = strDefpath & strDirname & "\" & strFilename 'create total string

Application.ScreenUpdating = False


 Sheets("Data").Select
    Application.CutCopyMode = False
    ActiveWindow.SelectedSheets.Delete
    
    
 Sheets("Front").Select
    Application.CutCopyMode = False
    ActiveWindow.SelectedSheets.Delete
    

    Sheets("Compliance by Trade lane").Select
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name"). _
        ClearAllFilters
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name").CurrentPage _
        = "BHX"

   


ActiveWorkbook.SaveAs Filename:=strPathname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

   
   
    Sheets("Compliance by Trade lane").Select
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name"). _
        ClearAllFilters
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name").CurrentPage _
        = "COR"

strDirname = Range("s6").Value ' New directory name




ActiveWorkbook.SaveAs Filename:=strPathname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

 
    Sheets("Compliance by Trade lane").Select
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name"). _
        ClearAllFilters
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name").CurrentPage _
        = "EXE"


ActiveWorkbook.SaveAs Filename:=strPathname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

    

    Sheets("Compliance by Trade lane").Select
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name"). _
        ClearAllFilters
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name").CurrentPage _
        = "GLA"



ActiveWorkbook.SaveAs Filename:=strPathname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

    
    Sheets("Compliance by Trade lane").Select
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name"). _
        ClearAllFilters
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name").CurrentPage _
        = "HUL"



ActiveWorkbook.SaveAs Filename:=strPathname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False


    Sheets("Compliance by Trade lane").Select
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name"). _
        ClearAllFilters
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name").CurrentPage _
        = "LAI"



ActiveWorkbook.SaveAs Filename:=strPathname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False



    Sheets("Compliance by Trade lane").Select
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name"). _
        ClearAllFilters
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name").CurrentPage _
        = "LEE"


ActiveWorkbook.SaveAs Filename:=strPathname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False


    Sheets("Compliance by Trade lane").Select
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name"). _
        ClearAllFilters
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name").CurrentPage _
        = "LHR1"

ActiveWorkbook.SaveAs Filename:=strPathname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False


    Sheets("Compliance by Trade lane").Select
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name"). _
        ClearAllFilters
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name").CurrentPage _
        = "LPL"

    


ActiveWorkbook.SaveAs Filename:=strPathname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False


    Sheets("Compliance by Trade lane").Select
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name"). _
        ClearAllFilters
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name").CurrentPage _
        = "MAN"


ActiveWorkbook.SaveAs Filename:=strPathname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False


    Sheets("Compliance by Trade lane").Select
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name"). _
        ClearAllFilters
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name").CurrentPage _
        = "MGP"

ActiveWorkbook.SaveAs Filename:=strPathname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False


    Sheets("Compliance by Trade lane").Select
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name"). _
        ClearAllFilters
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name").CurrentPage _
        = "PRO"



ActiveWorkbook.SaveAs Filename:=strPathname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False


    Sheets("Compliance by Trade lane").Select
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name"). _
        ClearAllFilters
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name").CurrentPage _
        = "SOU"



ActiveWorkbook.SaveAs Filename:=strPathname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False


    Sheets("Compliance by Trade lane").Select
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name"). _
        ClearAllFilters
    ActiveSheet.PivotTables("Pivot1").PivotFields("Branch Name").CurrentPage _
        = "SWI"



ActiveWorkbook.SaveAs Filename:=strPathname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
 
 

    Application.ScreenUpdating = False
    
    
    


End Sub