Filtering for Values not Currently in Data Set

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
714
Office Version
  1. 365
Platform
  1. Windows
I'm trying to run the below code, but I'm not getting any results. In playing with the code, it appears to be because there are no values of "Pending" at this point, but it is likely they will occur. How can I include the value in the filter so those values are captured if/when they are in the data set?

VBA Code:
                    With mN.UsedRange
                        .AutoFilter Field:=2, Criteria1:=Array("Approval", "Denial", "Pending")
                        .AutoFilter Field:=13, Criteria1:=Array("=", "")
                    End With
                    
                    mNLR = mN.Range("A" & Rows.Count).End(xlUp).Row
                    
                    If mNLR > 1 Then mN.Range("M2:M" & mNLR).SpecialCells(xlCellTypeVisible).Value = "Acceptable"
                    
                    'Clears the filter and resets the Last Row.
                    mN.AutoFilterMode = False
                    mNLR = mN.Range("A" & Rows.Count).End(xlUp).Row
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
How about

VBA Code:
With mN.UsedRange
    Dim hasPending As Boolean
    hasPending = WorksheetFunction.CountIf(.Columns(2), "Pending") > 0 'Change column as needed

    If hasPending Then
        .AutoFilter Field:=2, Criteria1:=Array("Approval", "Denial", "Pending")
    Else
        .AutoFilter Field:=2, Criteria1:=Array("Approval", "Denial")
    End If

    .AutoFilter Field:=13, Criteria1:=Array("=", "")
End With

mNLR = mN.Range("A" & Rows.Count).End(xlUp).Row

If mNLR > 1 Then mN.Range("M2:M" & mNLR).SpecialCells(xlCellTypeVisible).Value = "Acceptable"

mN.AutoFilterMode = False
mNLR = mN.Range("A" & Rows.Count).End(xlUp).Row
 
Upvote 0

Forum statistics

Threads
1,223,970
Messages
6,175,710
Members
452,667
Latest member
vanessavalentino83

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