Add a condition to a loop to check for date

Gblues

New Member
Joined
Aug 20, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I've got a sub routine that works to apply a filter to conditions in column I. I need to add another condition that would only apply to the list set if a date condition is met. Need the date checked for today in Column L before applying .

Sub AF()
Dim RX As Object, d As Object
Dim a As Variant
Dim i As Long

Const myList As String = "Z0|Z10|Z11|Z12|ZA|ZB1|ZB2|ZB3|ZB4|ZB5|AMD|ZP1|AMD" '<- Add more here if required

Set d = CreateObject("Scripting.Dictionary")
d.Comparemode = 1
Set RX = CreateObject("VBScript.RegExp")
RX.IgnoreCase = True
RX.Pattern = myList
a = Range("I2", Range("I" & Rows.Count).End(xlUp)).Value2
For i = 1 To UBound(a)
If RX.Test(a(i, 1)) Then d(a(i, 1)) = 1
Next i
Range("$A$1:$R$1").Resize(UBound(a)).AutoFilter Field:=9, Criteria1:=d.Keys, Operator:=xlFilterValues
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Or add another loop to identify where the date is not equal to today before applying the autofilter. Not sure how to accomplish this. I'm very new to VBA and macros.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
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