Change back color instead of font in textbox

bjornesto

New Member
Joined
Dec 8, 2012
Messages
4
Dear

I have made a search box through a command button to search for textboxes.
It changes also the font immediatly so that you fast notices where it is.

But because i have made a lot of textboxes and different fonts I need to only change the back color.

Ho does the code needs to be adjusted in the first code so that the background changes to orange background of the textbox?

Code:
Private Sub CommandButton1_Click()
Dim FindWhat As String, tb As TextBox
  On Error Resume Next
  FindWhat = InputBox("Find what?")
  If FindWhat = "" Then Exit Sub
  For Each tb In ActiveSheet.TextBoxes
      l = InStr(tb.Characters.Text, FindWhat)
      If l > 0 Then
         With tb.Characters(Start:=l, Length:=Len(FindWhat)).Font
                  .ColorIndex = 3
         .Bold = True
         End With
      End If
  Next
End Sub

How can i reset the background to white in the next command button
Code:
Private Sub CommandButton2_Click()
Dim FindWhat As String
  On Error Resume Next
  For Each tb In ActiveSheet.TextBoxes
         With tb.Characters.Font
         .ColorIndex = 0
         .Bold = False
         End With
  Next
Private Sub CommandButton2_Click()
 

Some videos you may like

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Watch MrExcel Video

Forum statistics

Threads
1,122,217
Messages
5,594,887
Members
413,947
Latest member
gizmolucy

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
Top