M

meg56

New Member
Joined
May 25, 2016
Messages
3
I'm an inexperienced Excel user and I have a very large set of data with the first column being the time of each entry. I know that to filter out a specific time range, I can use the Filter function. However, I have a large number of different time ranges to filter out. I would like to write a macro that can be adjusted to filter for different time ranges. For example, I want to find the data from 10:00:00 to 10:30:00, and then find the data from 2:00:00 to 2:30:00. Is it possible to do this on Excel? Would I be able to accomplish this in VBA? Currently, I only know how to write a macro that filters one specific time range. Any help is appreciated. Thanks for your time.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi meg56 - Welcome to the forum! I'm sure that what you want to do is possible. It may take a few iterations to get the date/time formats correct, but I know it can be done. You might try the code below and see if this helps us get started. Let us know how it goes. Good luck.

Code:
Sub meg56_SelectTime()
StartTime = InputBox("Enter Start Time")
EndTime = InputBox("Enter End Time")
'    ActiveSheet.Range("$A$1:$A$1000").AutoFilter Field:=1, Criteria1:=">=" & StartTime, _
'        Operator:=xlAnd, Criteria2:="<=" & EndTime
    ActiveSheet.Range("$A:$A").AutoFilter Field:=1, Criteria1:=">=" & StartTime, _
        Operator:=xlAnd, Criteria2:="<=" & EndTime
End Sub
 
Upvote 0
Hi goesr, thank you for the suggestion. I tried out this code, and it allowed me to input the start and end times I wanted. However, when I applied the filter, all of the data disappeared, even the data that fit my criteria. I made sure the range included all of my cells as well, so I'm not sure why this happened. Any advice would be appreciated- thanks so much.
 
Upvote 0
Update: I played with the time formats and the code works. Thanks very much for the help.
 
Upvote 0
Hi meg56 - GREAT. I'm glad you were able to get it to work. Those date/time formats can be tricky, but once you get the right format it should work. Thanks for the feedback. Often we don't hear if our suggestions work or not. Have a great long weekend!
 
Upvote 0

Forum statistics

Threads
1,215,779
Messages
6,126,846
Members
449,343
Latest member
DEWS2031

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