Referencing code to a specific cell in Sheet1

Nick70

Active Member
Joined
Aug 20, 2013
Messages
304
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

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
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,701
Messages
6,126,311
Members
449,308
Latest member
Ronaldj

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