Filter date with time

0 votes

I'm attempting to filter one of the columns where the hour needs to be greater than 7 am and smaller than 19 pm, and the date needs to be today's date or a specified date.

This is how my data set looks: 2023/03/17 16:00

I am trying to use the following code:

Sub FilterInicioDeTurnoDAY()
Dim in_time As Double, out_time As Double, dtToday As Date

dtToday = Date
in_time = dtToday + TimeValue("07:00")
out_time = dtToday + TimeValue("18:59")


 Sheets("PegarCitas_INICIOdeTURNO").Select
 
 ActiveSheet.Range("E:E").AutoFilter Field:=34, Operator:=xlAnd, Criteria1:=">=" & in_time, Criteria2:="<=" & out_time

End Sub

However, running the macro does not filter the values I need. What am I doing wrong?

Mar 19, 2023 in Others by narikkadan
• 63,640 points
447 views

1 answer to this question.

0 votes

Try this:

Sub FilterInicioDeTurnoDAY()
   Dim in_time As Double, out_time As Double, dtToday As Date
   
   dtToday = Date
   in_time = dtToday + TimeValue("07:00")
   out_time = dtToday + TimeValue("18:59")
   Me.Range("E:E").AutoFilter Field:=34, Operator:=xlAnd, _
                   Criteria1:=">=" & Format(in_time, "yyyy/mm/dd hh:mm"), _
                   Criteria2:="<=" & Format(out_time, "yyyy/mm/dd hh:mm")
End Sub
answered Mar 19, 2023 by Kithuzzz
• 38,000 points

Related Questions In Others

0 votes
1 answer
0 votes
0 answers

Date time convert in Replace activity in word document scope

we have input in excel  New date/Header 31/12/2020 31/12/2019 We  want ...READ MORE

Jun 22, 2020 in Others by Sapna
• 120 points

recategorized Jun 22, 2020 by Gitika 459 views
0 votes
1 answer

How do I get the current date and time in PHP?

The time would go by your server ...READ MORE

answered Feb 16, 2022 in Others by Aditya
• 7,680 points
704 views
0 votes
1 answer

How to get current time and date in Android

In order to get the current date ...READ MORE

answered Feb 23, 2022 in Others by Aditya
• 7,680 points
2,125 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
1,183 views
0 votes
1 answer

How to load file to Excel Power query from SFTP site

Currently, I don't think there is a ...READ MORE

answered Dec 3, 2018 in Power BI by Upasana
• 8,620 points
3,635 views
0 votes
1 answer

Using VBA Excel to create a gramatically correct list

The Excel AND function is a logical ...READ MORE

answered Feb 9, 2022 in Others by gaurav
• 23,260 points
882 views
0 votes
2 answers

How to copy a formula horizontally within a table using Excel VBA?

Hi so basically, create an adjacent column ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,690 points
1,039 views
0 votes
1 answer

Copy data with filter applied using Excel VBA

Try this: Private Sub CommandButton1_Click() Dim ...READ MORE

answered Mar 19, 2023 in Others by Kithuzzz
• 38,000 points
517 views
0 votes
1 answer

Exclude worksheets from loop with a list

You can achieve this by making a ...READ MORE

answered Feb 11, 2023 in Others by Kithuzzz
• 38,000 points
321 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP