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()
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,215,119
Messages
6,123,172
Members
449,094
Latest member
bes000

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