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

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Try

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

Forum statistics

Threads
1,216,075
Messages
6,128,667
Members
449,462
Latest member
Chislobog

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