2

I wrote a macro to search through a filter for an exact match in column A and it needs an approximate match for a search in column B. Right now I only have it as an exact match, and I need help making it an approximate match code. Below is my code:

Sub SearchBox1()

Dim myButton As OptionButton
Dim MyVal As Long
Dim sht As Worksheet
Dim myField As Long
Dim DataRange As Range
Dim mySearch As Variant

'Load Sheet into A Variable
 Set sht = ActiveSheet

'Unfilter Data (if necessary)
 On Error Resume Next
    sht.ShowAllData
 On Error GoTo 0

 'Filtered Data Range (include column heading cells)
  ActiveSheet.Range("$A50:$L$130").AutoFilter Field:=2, Criteria1:=sht.Shapes("CountrySearch").TextFrame.Characters.Text
  Exit Sub

End Sub

Thank you for your help!

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Tyler
  • 31
  • 1

1 Answers1

1

Try changing Criteria1 to this

if it's searching for a string:

Criteria1:= "*" & sht.Shapes("CountrySearch").TextFrame.Characters.Text & "*"

or, if you have numbers

Criteria1:= ">=" & sht.Shapes("CountrySearch").TextFrame.Characters.Text

paul bica
  • 10,557
  • 4
  • 23
  • 42