Autofilter with Startdate and Enddate by Inputbox

MHD

New Member
Joined
Mar 16, 2021
Messages
49
Office Version
  1. 2019
Hello all
Please help in debugging this code

With this code, I want to filter one of the columns in my table that contains a date.
Using the input box to specify the start date and end date

VBA Code:
Sub TEST()


    Dim StartDate As Date, EndDate As Date
    
    
    StartDate = Application.InputBox(MsgGP, TitleMsg, FormatDateTime(Date, vbShortDate), Type:=1)
    EndDate = Application.InputBox(MsgGP, TitleMsg, FormatDateTime(Date, vbShortDate), Type:=1)
    
    
    ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=4, _
                                                Criteria1:=">=" & StartDate, _
                                                OOperator:=xlAnd, _
                                                Criteria2:="<=" & EndDate
End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Looking at your code you have a Typo
Rich (BB code):
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=4, _
                                                Criteria1:=">=" & StartDate, _
                                                OOperator:=xlAnd, _
                                                Criteria2:="<=" & EndDate

Dave
 
  • Like
Reactions: MHD
Upvote 0
Solution
Looking at your code you have a Typo
Rich (BB code):
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=4, _
                                                Criteria1:=">=" & StartDate, _
                                                OOperator:=xlAnd, _
                                                Criteria2:="<=" & EndDate

Dave
Thanks
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,738
Members
448,988
Latest member
BB_Unlv

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