Hey All,
I have a series of command buttons in a spreadsheet that initiate an inputbox to search various autofilters for user defined queries. The problem is if I hit cancel on the input box all the autofilters on the sheet dissappear...I have included a couple examples of the code I am using for to manage the user defined queries.
Example 1
Example 2
How can I prevent the autofilters from dissappearing when a user hits cancel on the inputbox?
I have a series of command buttons in a spreadsheet that initiate an inputbox to search various autofilters for user defined queries. The problem is if I hit cancel on the input box all the autofilters on the sheet dissappear...I have included a couple examples of the code I am using for to manage the user defined queries.
Example 1
Code:
Sub daterange()
'
' daterange Macro
'
Dim strName1 As Variant, strName2 As Variant
Dim caption As String
Dim Prompt As String
Prompt = ""
caption = "Approval Date Range Search"
On Error GoTo Errorline
strName1 = DateValue(Application.InputBox(Prompt & " Enter 'START' date (dd/mm/yyyy)", caption, Type:=2))
strName2 = DateValue(Application.InputBox(Prompt & " Enter 'END' date (dd/mm/yyyy)", caption, Type:=2))
If strName1 = "False" Or strName2 = "False" Then Exit Sub
Range("Table_owssvr_1[Approval Date]").Select
Selection.AutoFilter Field:=6, Criteria1:=">=" & CLng(strName1), Criteria2:="<=" & CLng(strName2), Operator:=xlAnd
Exit Sub
Errorline:
ActiveSheet.ListObjects("Table_owssvr_1").Range.AutoFilter Field:=6
End Sub
Example 2
Code:
Sub ksearch()
'
' ksearch Macro
'
Dim strName As String
Dim caption As String
Dim Prompt As String
Prompt = "Enter keyword"
caption = "Keyword Search"
strName = (InputBox(Prompt, caption))
Range("Table_owssvr_1[Keywords]").Select
If strName = "" Then
Selection.AutoFilter
Else
Selection.AutoFilter Field:=5, Criteria1:="=*" & strName & "*", Operator:=xlAnd
End If
End Sub
How can I prevent the autofilters from dissappearing when a user hits cancel on the inputbox?