Advanced FIlter Criteria using multiple rows and single header.

Rfriend

Board Regular
Joined
May 10, 2021
Messages
73
Office Version
  1. 2010
Platform
  1. Windows
Hello,

I am trying to use an advanced filter to return all values in a criteria range. I can get data for the values in the criteria, but I cannot get the filter to not return values for the range cells that are blank. Listbox 1 & 2 are fine. But listbox3 filters on a single column with up to 13 related codes. It sees the blank cells as returns all personnel instead of only returning values for the jobcclass that have a value. Since the criteria for each job is different, the list of jobclass codes returned will change anywhere between 1 to 13 codes. My code is below. Any help is appreciated.

For Example:
  • I select either vacant or active positions in lstbox1 using an advfilter.
  • Double click the position in lstbox1 which inserts the jobclass into the txtbox "Search Job Class" on the user form.
  • Click search to see a list of all the positions and their corresponding job description requirements that would be considered for promotion to the vacant position.
  • Show all available active staff that possess any of the jobclasses in lstbox2 and sort them by years of service, or seniority.
VBA Code:
Sub AdvFilterVaclstBox1()
    Sheets("Staff_Data").Range("Table735[#All]").AdvancedFilter Action:= _
        xlFilterCopy, CriteriaRange:=Range("VacantOut!Criteria"), CopyToRange:= _
        Range("VacantOut!Extract"), Unique:=False
End Sub

Sub AdvFilterVaclstBox2()
    With Sheet14
        Range("Table297[#All]").AdvancedFilter Action:=xlFilterCopy, CriteriaRange _
        :=Range("JDOut!Criteria"), CopyToRange:=Range("Table21[#All]"), Unique:= _
        False
    Range("Table21").Select
    Selection.Copy
    Range("V11").Select
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
    End With
End Sub

Sub AdvFilterVaclstBox3()
    Sheets("Staff_Data").Range("Table735[#All]").AdvancedFilter Action:= _
        xlFilterCopy, CriteriaRange:=Range("JDOut!Criteria"), CopyToRange:=Range( _
        "V27:AN27"), Unique:=False
End Sub


Private Sub cmdSearchStatus_Click()
    Dim Status As Variant
        On Error GoTo errHandler:
        lstBox1.RowSource = ""
    Set Status = cboSearchStatus
        Application.ScreenUpdating = False
    If Me.cboSearchStatus.Value = "Active" Or Me.cboSearchStatus.Value = "Inactive" Or Me.cboSearchStatus.Value = "Vacant" Then
     Sheet3.Range("D5").Value = Me.cboSearchStatus.Value
     AdvFilterVaclstBox1
    If Sheet3.Range("C9").Value = "" Then
        lstBox1.RowSource = ""
    Else
        lstBox1.RowSource = "VacantOut"
    End If
        Exit Sub
    End If
        AdvFilterVaclstBox1
    If Sheet3.Range("C9").Value = "" Then
        lstBox1.RowSource = ""
    Else
      lstBox1.RowSource = "VacantOut"
    End If
      On Error GoTo 0
    Exit Sub
errHandler:
    MsgBox "No match found for " & cboSearchStatus.Value
    Me.lstBox1.RowSource = ""
    Exit Sub
End Sub

Private Sub cmdJDLookup_Click()
    Dim JobClass As Long
    Dim JDOutSH As Worksheet
    Dim Staff_Data As Worksheet
        On Error GoTo errHandler:
    Set JDOutSH = Sheet14
    Set Staff_Data = Sheet7
    JobClass = Me.CS2.Value
        JDOutSH.Range("C7").Value = Me.CS2.Value
    Application.ScreenUpdating = False
        lstBox2.RowSource = "JDSrchNew"
        'Transpose
    With Sheet14
        If CS2.Value = "" Then
            .Range("C7").Value = ""
        Else
            .Range("C7").Value = CS2
        End If
    End With

        If Sheet14.Range("C7").Value = "" Then
            lstBox2.RowSource = ""
        Else
            lstBox2.RowSource = "JDSrchNew"
        End If
        
        If Sheet14.Range("C7").Value = "" Then
            lstSelector.RowSource = ""
        Else
            lstSelector.RowSource = "PotentialStaff"
        End If
            AdvFilterVaclstBox2
                AdvFilterVaclstBox3
                   lstBox2.RowSource = Sheet14.Range("JDSrchNew").Address(external:=False)
                lstSelector.RowSource = Sheet14.Range("PotentialStaff").Address(external:=True)
        Exit Sub
errHandler:
    MsgBox "No match found for " & txtSearchTrng2.Text
        On Error GoTo 0
    Exit Sub
End Sub
 

Attachments

  • Vacancy Pic1.jpg
    Vacancy Pic1.jpg
    194.4 KB · Views: 19
  • Vacancy Pic3.jpg
    Vacancy Pic3.jpg
    151.8 KB · Views: 23
  • Vacancy Pic2.gif
    Vacancy Pic2.gif
    110.3 KB · Views: 19

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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