VBA Advanced Filter

raccoon588

Board Regular
Joined
Aug 5, 2016
Messages
118
I have some code that currently looks for two criteria.
Date RequestedApproved?
2/24/2019Approved

<colgroup><col><col></colgroup><tbody>
</tbody>

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
 

Some videos you may like

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

jjasmith4

New Member
Joined
Aug 22, 2018
Messages
48
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:

raccoon588

Board Regular
Joined
Aug 5, 2016
Messages
118
Thank you so much, I didn't realize i had to add the date again with the pending criteria.
 

jjasmith4

New Member
Joined
Aug 22, 2018
Messages
48
Yes: each row is independent. On row 1 all conditions must be true OR on row 2 all conditions must be true, etc.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,521
Messages
5,596,653
Members
414,083
Latest member
Mrsash

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
Top