VBA Advanced Filter

raccoon588

Board Regular
Joined
Aug 5, 2016
Messages
118
I have some code that currently looks for two criteria.
[TABLE="width: 205"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]Date Requested[/TD]
[TD]Approved?[/TD]
[/TR]
[TR]
[TD]2/24/2019[/TD]
[TD]Approved
[/TD]
[/TR]
</tbody>[/TABLE]

I would like to add pending as a criteria under approved too. so that if the column has approved or pending it will show up. bellow is what i have for code and it works great for just showing lined that have approved. i cant seem to make the proper adjustment to get it to pull in approved and pending.




Code:
Sub Sort()
Dim i As Long
Dim j As Long
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
  For i = 4 To 4
    For j = 12 To 86 Step 2
      With Sheets("RequestLog").Columns("A:G")
        .AdvancedFilter Action:=xlFilterCopy, _
        CriteriaRange:=Range("Calendar!" & Nb2Let(j) & i & ":" & Nb2Let(j + 1) & i + 1), CopyToRange:=Range("Calendar!" & Nb2Let(j) & i + 4 & ":" & Nb2Let(j + 1) & i + 100), Unique:=False
      End With
    Next j
  Next i
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub


Private Function Nb2Let(lng As Long) As String
'Convert To Column Letter
  Nb2Let = Split(Cells(1, lng).Address, "$")(1)
End Function
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
You might be able to change "Approved" to "Approved or Pending". If not, enter "Pending" under "Approved", copy the date down next to it, and then in your code increase the criteria range one row:

Old: CriteriaRange:=Range("Calendar!" & Nb2Let(j) & i & ":" & Nb2Let(j + 1) & i + 1)
New: CriteriaRange:=Range("Calendar!" & Nb2Let(j) & i & ":" & Nb2Let(j + 1) & i + 2),
 
Last edited:
Upvote 0
Yes: each row is independent. On row 1 all conditions must be true OR on row 2 all conditions must be true, etc.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
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