to make filter on data coulmn by using value in excel

shmouel99

New Member
Joined
May 1, 2012
Messages
29
hello
i have 2 date values in excel spreadsheet ( i must use it by the sheet) and i want to flter table by the date coulmn and AutoFilter, when the start date and the end date will be taken from the sheet itself.

but when i defined date varible like starta and edit the filter (Criteria1:=">=starta") it didt work (the value was starta and not the date in the starta)
how to edit it?
thanks


sub abcd
Dim starta As Date, enda As Date
starta = Worksheets("periods and options").Range("a1").Value
enda = Worksheets("periods and options").Range("b1").Value
Sheets("DATAF").Range("a1:p1325").Select


Selection.AutoFilter Field:=1, Criteria1:=">=starta", Operator:=xlAnd _
, Criteria2:="<=enda"
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Try

Code:
Selection.AutoFilter Field:=1, Criteria1:=">=" & starta, Operator:=xlAnd, Criteria2:="<=" & enda
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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