Hilite Searched Text/String in Textbox1 when you type the lookfor string in Textbox2

SamDsouza

Board Regular
Joined
Apr 16, 2016
Messages
205
Hi
Anyone

Is this Technical issue of hiliting a string or text in Textbox1 when you have typed the word "the" in Textbox2.
Because there is no Blue colour of Hilited Text in Textbox1 or rather no Hilite Colour of String Searched in textbox1

When text "the" typed in Textbox2 it should hilite at two places in Textbox1 "The Brown Fox quickly jumped over the lazy Dog"

VBA Code:
Option Explicit

Private Sub UserForm_Initialize()
Dim strText As String
strText = "The Brown Fox quickly jumped over the lazy Dog"
Textbox1.text = strText
End Sub

Private Sub CommandButton_Click()

Dim OldString As String
Dim OldPos As Integer

Dim NewPos As Integer

NewPos = InStr(OldPos + 1, Textbox1.Text, Textbox2.Text, vbTextCompare)
If NewPos = 0 Then
     MsgBox "No more matches!"
  Else
     Textbox1.SelStart = NewPos
     Textbox1.SelLength = Len(Textbox2.Text)
End If
OldString = Textbox2.Text
OldPos = NewPos

End Sub
Your help will always be apprciated
SamD
190
 
Last edited:

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
You can't select two separate parts of a textbox on a form.
 
Upvote 0
You want your code to select both instances of 'the' in your textbox, and I'm saying you cannot do that.
 
Upvote 0
You want your code to select both instances of 'the' in your textbox, and I'm saying you cannot do that.

Why Not in VBA ? If same result is derived from Userform Textboxes of VB4 or VB6 Exactly i dont remember

Sir, How can i derive what i want

SamD
192
 
Upvote 0
Because you can't. If you need more than that, ask Microsoft. The userforms in VBA are not the same as the forms in VB6.
 
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,732
Members
449,093
Latest member
Mnur

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