Excel search and highlight box

blewbot

New Member
Joined
Jun 7, 2011
Messages
14
ok here is what i have... i have a active x label that when clicked opens search box and says enter last name to search schedule...basically i want it to highlight all of those last names in the schedule.

that part works great if it is an exact match, but if there is anything else in the cell it will not highlight the cell.

so my question is how to i adjust this from...

[If MyVal.Value = MySearch Then]

to something more like...

[If MyVal.Value "kinda sorta close to"= MySearch Then]

Thanks for the needed help

Code:
Private Sub Label1_Click()
Dim MyVal As Range
Dim MySearch As String
 
MySearch = Application.InputBox("ENTER LAST NAME TO search SCHEDULE", "SEARCH DOWS")
 
    For Each MyVal In Range("C3:O7")
         If MyVal.Value = MySearch Then
            MyVal.Interior.Color = vbYellow
            Else
            MyVal.Interior.Color = vbWhite
            End If
        Next
 
For Each MyVal In Range("C9:O18")
       If MyVal.Value = MySearch Then
            MyVal.Interior.Color = vbYellow
            Else
            MyVal.Interior.Color = vbWhite
            End If
        Next
 
For Each MyVal In Range("C20:O29")
       If MyVal.Value = MySearch Then
            MyVal.Interior.Color = vbYellow
            Else
            MyVal.Interior.Color = vbWhite
            End If
        Next
 
End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
BUMP

I could really use help with this, anyone know where i am going wrong... i tired the "like" instead of "=" but it still only return exact matches
 
Upvote 0
Hi,

Maybe this

Code:
       If InStr(1, MyVal.Value, mySearch) Then
            MyVal.Interior.Color = vbYellow
        Else
            MyVal.Interior.Color = vbWhite
        End If

HTH

M.
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,445
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top