Good Morning,
I hope you all are doing well.
I was hoping that someone can perhaps show me how do I add code to exit the sub when the cancel button is selected on the InputBox. I have tried I few option on the forum, but do not seem to get it working. I am very new to vba and perhaps are missing the obvious.
I am filtering a list of data populated in sheet3 to only show certain data entries based on date values. this is working fine, but when I hit cancel the code is still running as if I entered a "0" for the days.
Your help would be highly appreciated.
I thank you in advance.
Sub Filter()
Dim i As Integer
Dim UseEnt As String
Sheets("Sheet3").Activate
ActiveSheet.AutoFilterMode = False
On Error Resume Next
i = InputBox("Enter the number of days for the search.")
If i Like "" Then
ActiveSheet.AutoFilterMode = False
Exit Sub
End If
UseEnt = Date - i
Range("A2").CurrentRegion.AutoFilter Field:=3, Criteria1:="<=" & UseEnt
Application.CutCopyMode = False
End Sub
Bookmarks