Highlight Existing Text in TextBox

steve1262

Board Regular
Joined
Aug 19, 2006
Messages
126
I have an Embeded TextBox in my worksheet. Can anyone tell me how to highligh the existing text in the TextBox when the user first enters it.

I want it to hightlight it so when the user starts typing new text the old text is cleared.

I have tryed a few things but have not had any luck.

Thank you for any help.

Steve
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
<table width="100%" border="1" bgcolor="White" style="filter:progid:DXImageTransform.Microsoft.Gradient(endColorstr='#C0CFE2', startColorstr='#FFFFFF', gradientType='0');"><tr><TD><font size="2" face=Courier New>  <font color="#008000">'you will need both of these if the textbox does not have a</font>
  <font color="#008000">'GotFocus event. This would be the case in a userform</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Sub</font> TextBox1_Enter()
       TextBox1.SelStart = 0
       TextBox1.SelLength = Len(TextBox1.Text)
  <font color="#0000A0">End</font> <font color="#0000A0">Sub</font>

  <font color="#0000A0">Private</font> <font color="#0000A0">Sub</font> TextBox1_MouseDown(ByVal Button <font color="#0000A0">As</font> Integer, <font color="#0000A0">ByVal</font> Shift <font color="#0000A0">As</font> Integer, <font color="#0000A0">ByVal</font> X <font color="#0000A0">As</font> Single, <font color="#0000A0">ByVal</font> Y <font color="#0000A0">As</font> Single)
       TextBox1.SelStart = 0
       TextBox1.SelLength = Len(TextBox1.Text)
  <font color="#0000A0">End</font> <font color="#0000A0">Sub</font>

  <font color="#008000">'in a worksheet</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Sub</font> TextBox1_GotFocus()
       TextBox1.SelStart = 0
       TextBox1.SelLength = Len(TextBox1.Text)
  <font color="#0000A0">End</font> <font color="#0000A0">Sub</font>
</FONT></td></tr></table><button onclick='document.all("10212006233310406").value=document.all("10212006233310406").value.replace(/<br \/>\s\s/g,"");document.all("10212006233310406").value=document.all("10212006233310406").value.replace(/<br \/>/g,"");window.clipboardData.setData("Text",document.all("10212006233310406").value);'>Copy to Clipboard</BUTTON><textarea style="position:absolute;visibility:hidden" name="10212006233310406" wrap="virtual">
'you will need both of these if the textbox does not have a
'GotFocus event. This would be the case in a userform
Private Sub TextBox1_Enter()
TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1.Text)
End Sub

Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1.Text)
End Sub

'in a worksheet
Private Sub TextBox1_GotFocus()
TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1.Text)
End Sub</textarea>
 
Upvote 0

Forum statistics

Threads
1,214,601
Messages
6,120,465
Members
448,965
Latest member
grijken

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