Referencing code to a specific cell in Sheet1

Nick70

Active Member
Joined
Aug 20, 2013
Messages
299
Office Version
  1. 365
Platform
  1. Windows
Hi,

I would like to amend this code so that the criteria2 references to a date in cell A2 Sheet1 (which would contain date 12/1/2023).

VBA Code:
Option Compare Text
Sub test()

With Range("A3:d" & Cells(Rows.Count, "A").End(xlUp).Row)
k = .Find("DATE", lookat:=xlWhole).Column
        .AutoFilter k, Criteria1:=">=7/1/2023", Operator:=xlAnd, Criteria2:="<12/1/2023"
    End With
End Sub

How would I do that?

Thanks,
N.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Perhaps:
VBA Code:
Option Compare Text
Sub test()

Dim cr as String
cr = Format(Sheets("Sheet1").Range("A2").Value,"m/d/yyyy")

With Range("A3:d" & Cells(Rows.Count, "A").End(xlUp).Row)
    k = .Find("DATE", lookat:=xlWhole).Column
        .AutoFilter k, Criteria1:=">=7/1/2023", Operator:=xlAnd, Criteria2:="<" & cr
End With

End Sub
 
Upvote 0
Solution
You are welcome.
Glad I could help!
 
Upvote 0

Forum statistics

Threads
1,215,081
Messages
6,123,016
Members
449,093
Latest member
ikke

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