ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Highlight Value of Text Box (https://www.excelbanter.com/excel-programming/331627-highlight-value-text-box.html)

ben

Highlight Value of Text Box
 
I have a UserForm with four textboxes names py1 py2 py3 py4
What I am trying to accomplish is that when a user clicks into a textbox, it
will loop through the other three add their values and subtract it from a
Total, and put that value into the textbox. This part I have accomplished
with no problem.
However when it puts that value into the textbox the user has clicked into i
want to HIGHLIGHT the value that was entered into textbox through VBA

..selstart & .sellength will not select it code follows


Private Sub py1_Enter()
Dim t As Integer
toy = 0
Set ctl1 = Me.ActiveControl
For t = 1 To 4
Set ctll = Me.Controls("py" + Trim(Str(t)))
If ctl1.Name < ctll.Name Then toy = toy + Val(ctll.Text)
Next
With ctl1
..Text = Trim(Str(tow - toy))
..SelStart = 0
..SelLength = Len(.Text)
End With
End Sub

the code is EXACTLY the same for each text box
the two variables ctll & ctl1 are public in the userform.
anyone see why maybe the userform will not highlight the text?


--
When you lose your mind, you free your life.

Simon Lloyd[_627_]

Highlight Value of Text Box
 

Hi i think you need to SetFocus = Textbox? or something along thos
lines

Simo

--
Simon Lloy
-----------------------------------------------------------------------
Simon Lloyd's Profile: http://www.excelforum.com/member.php...nfo&userid=670
View this thread: http://www.excelforum.com/showthread.php?threadid=37868



All times are GMT +1. The time now is 12:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com