route217
asked on
Macro to run from pop up window..
Hi Experts Using Excel 2010
I have the following macro (see attached workbook) which works fine. But it's restricted in a sense that it is specific to column AC...I want to have the option to select which ever column I want...then run the macro.
Via pop up window..
test-data.xlsx
I have the following macro (see attached workbook) which works fine. But it's restricted in a sense that it is specific to column AC...I want to have the option to select which ever column I want...then run the macro.
Via pop up window..
test-data.xlsx
ASKER
Public Sub MyFilter()
Dim lngStart As Long, lngEnd As Long
lngStart = Range("B2").Value 'assume this is the start date
lngEnd = Range("B3").Value 'assume this is the end date
'assume you have field name / label in D5
Range("AC6:AC30").AutoFilter field:=1, _
Criteria1:=">=" & lngStart, _
Operator:=xlAnd, _
Criteria2:="<=" & lngEnd
End Sub
How do you want to be able to identify the column to be filtered, from a cell or a user input?
Is it coincidence that the Start Date and the date in column AC are the same or will that always be the case? If that is the case then a Find command could be used to find the correct column.
Is it coincidence that the Start Date and the date in column AC are the same or will that always be the case? If that is the case then a Find command could be used to find the correct column.
ASKER
User input....ignore the start date and column header
So what will the user input to determine which column?
ASKER
The Column ie AC or AD...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent feedback
Happy to help.
Just found this in another question to check the user entry is valid:
ColName = InputBox("Which column to filter?", "Column")
If Not ColName Like "[A-Za-z]" Then
MsgBox "Wrong input"
Exit Sub
End If
This will exit the routine when a duff entry is input, the user will have to click the button again to enter another choice.
ColName = InputBox("Which column to filter?", "Column")
If Not ColName Like "[A-Za-z]" Then
MsgBox "Wrong input"
Exit Sub
End If
This will exit the routine when a duff entry is input, the user will have to click the button again to enter another choice.
For ease of uploading, please copy and paste the code into a snippet on a comment rather than a new file.