Filtering for Values not Currently in Data Set

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
701
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

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
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,215,093
Messages
6,123,068
Members
449,091
Latest member
remmuS24

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