Advance Filter Macro from Pivot Table selection

TBP

Board Regular
Joined
Jul 30, 2011
Messages
55
Hi,
Im using this code I found on the web to create separate reports from 1 table and was wonder if I could choose what reports to make from a selection in a pivot table rather than the range "CompanyList".
The pivot table would show all company's in the data and I could just filter out any I didn't require.

Also is there a way to create a sub directory in the current path like "Reports" if there inst already one.

Thanks

Link to example workbook I made up to test
https://onedrive.live.com/redir?resid=6c9e7e05ee40ba3a!127&authkey=!ANJi4GsLu10Nkio&ithint=file%2cxlsm

Code:
Option Explicit

Sub CreateSeparateFiles()
    
    Dim cell As Range
    Dim curPath As String
    
    curPath = ActiveWorkbook.Path & "\"
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    For Each cell In Range("CompanyList")
        [CriteriaField] = cell.Value
        Range("DataAll").AdvancedFilter Action:=xlFilterCopy, _
            criteriarange:=Range("Criteria"), copyToRange:=Range("Extract"), unique:=False
        Range(Range("Extract"), Range("Extract").End(xlDown)).Copy
        Workbooks.Add
        ActiveSheet.Paste
        Range("A1").Select
        ActiveSheet.ListObjects.Add(xlSrcRange, Range(Selection, ActiveCell.SpecialCells(xlLastCell)), , xlYes).Name = _
        "Table1"
        Range("A1").Select
        ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleMedium2"
        ActiveWorkbook.SaveAs Filename:=curPath & cell.Value & " In Transit " & Format(Now, "dmmmyyyy") & ".xlsx", _
            FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
        ActiveWindow.Close
        Range(Range("Extract"), Range("Extract").End(xlDown)).ClearContents
    Next cell
    
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

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