Macro for pop up message box for auto-filter entry

R

Roady

Hello:

I have a spreadsheet with auto-filters. I would like to create a macro
button that works as a shortcut for those who would like to perform a certain
search function so that the users do not have to remember how to filter- all
they will need to do is enter in a series of numbers in a pop-up message box
and then hit 'ok'.

Steps are as follows:

Select auto-filter drop-down on Col. A
Select 'custom filter'
Select dropdown 'Contains'
{Enter in the string of numbers that user has entered into the popup box
into the box at right}
Select 'or' button
Select dropdown 'Equals'
{Again, enter in the string of numbers that user has entered into the popup
box into the box at right}
Hit 'Ok' button

Can you help with coding? thank you!
 
L

Luke M

You can enter this macro into the VBA editor, and then create a button (from
forms toolbar, or an picture from drawing toolbar) and link the macro to it.

Sub FilterChoice()

Dim Choice1 As String
Dim Choice2 As String


'Input box format is question, title
Choice1 = InputBox("What is the first string?", "First String")
Choice2 = InputBox("What is the second string?", "Second String")

'Field number equals column number, where A = 1, B = 2, etc.
Selection.AutoFilter Field:=1, Criteria1:="=*" & Choice1 & "*",
Operator:=xlOr, _
Criteria2:="=" & Choice2
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top