Excel VBA: Filter with multiple criteria ranges

gd6noob

Board Regular
Joined
Oct 20, 2017
Messages
170
Office Version
  1. 2016
Platform
  1. Windows
Hi guys,

Just had a question on how to filter this correctly.
On my dahsboard tab, I have a bunch of criteria that the user can input.
On my panorama tab, is the dataset that needs to be filter according to the the range on the dashboard tab.

Quebec Callem All.xlsb
HIJKLM
4Location: Location NameFCLM AreaShift PatternDepartmentPayroll Employee StatusEmployee Type
5YUL213NA1299030ActiveHourly
6DA
7DL
8
9
10
Dashboard

Quebec Callem All.xlsb
ABCDEFGHIJKL
1Location: Location NameEmployee IdLoginFirst NameLast NamePayroll Employee StatusShift PatternDepartmentFCLM AreaEmployee TypeLast Hire DateMobile Phone - Private
2
3
4
Panorama


VBA Code:
Sub filtercopy()
    Dim cwb As Workbook, nwb As Workbook
    Dim rgData As Range, rgCriteria As Range, rgOutput As Range

    Set cwb = ThisWorkbook
    Set rgData = cwb.Worksheets("Panorama").Range("A2").CurrentRegion
    Set rgCriteria = cwb.Worksheets("Dashboard").Range("H5").CurrentRegion
 
    Workbooks.Add
    Set nwb = ActiveWorkbook
    Set rgOutput = nwb.Worksheets("Sheet1").Range("A1")
 
        rgData.AdvancedFilter xlFilterCopy, rgCriteria, rgOutput
    Call sbSaveExcelDialog
    nwb.Close
End Sub
VBA Code:
Sub sbSaveExcelDialog()
    Dim Fldr As String, fname As String
 
    With Application.FileDialog(4)
        .AllowMultiSelect = False
        If .Show <> -1 Then Exit Sub
        Fldr = .SelectedItems(1)
    End With
 
    fname = ThisWorkbook.Worksheets("Dashboard").Range("C11")
    ActiveWorkbook.SaveAs Filename:=Fldr & "\" & fname & ".xls", FileFormat:=xlNormal

End Sub

I have have it set so that when it filters, it would open a new workbook and ask the user to save. that is working but I noticed that after the filter, it gives me a lot less data then if I manually filter. I guess Advanced Filter works only a single row for the criteria?

the number of criteria will vary, example, usually the location will be 1 single place, while the FCLM Area and Shift Pattern will always be different with no set amount.

Any help would be much appreciated.
 
Last edited:

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
In an Advanced Filter Criteria Table, each criteria in a single row is an AND. Each row is an OR.

In your current table, only the first row has a location, area, and department. In the other rows, those same criteria are blank. They need to be repeated.
Location: Location NameFCLM AreaShift PatternDepartmentPayroll Employee StatusEmployee Type
YUL213NA
1299030​
ActiveHourly
YUL213DA
1299030​
ActiveHourly
YUL213DL
1299030​
ActiveHourly
 
Upvote 0
In an Advanced Filter Criteria Table, each criteria in a single row is an AND. Each row is an OR.

In your current table, only the first row has a location, area, and department. In the other rows, those same criteria are blank. They need to be repeated.
Location: Location NameFCLM AreaShift PatternDepartmentPayroll Employee StatusEmployee Type
YUL213NA
1299030​
ActiveHourly
YUL213DA
1299030​
ActiveHourly
YUL213DL
1299030​
ActiveHourly
ohh.. then using advanced filter isnt the way to go, because within each department, they will have a different FCLM area # and a different shift pattern. I would need to have 1 line for each to cover all the variables..

Using autofilter is the best option? if not, whats the best option?
 
Upvote 0
IF you want all FCLM Areas and all Shift Patterns for a given Department, then just leave them blank.

Autofilter may be easier. I don't fully appreciate the nature of your data and what you are filtering for.
 
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,443
Members
448,898
Latest member
drewmorgan128

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