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"
Your help will always be apprciated
SamD
190
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
SamD
190
Last edited: