ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   UserForm Control Question (https://www.excelbanter.com/excel-programming/431896-userform-control-question.html)

Mark Knutson

UserForm Control Question
 
I have fifteen text boxes in my userform. They have a default value of
zero. When my form loads, the first text box has the focus. I want to
highlight or select the zero so when I enter a number into the text box
it will overwrite the zero rather then put the number after the zero. I
can't figure out the code I need to highlight the zero.

The following text boxes highlight the zero automatically when I press
enter in the previous text boxes. So I just need to be able select the
first text boxes zero. Any help will be appreciated. Thanks in advance.
By the way I have excel 2003. Thanks, Mark

Rick Rothstein

UserForm Control Question
 
This UserForm Initialize event code should do what you want...

Private Sub UserForm_Initialize()
With TextBox1
.SelStart = 0
.SelLength = Len(.Text)
End With
End Sub

--
Rick (MVP - Excel)


"Mark Knutson" wrote in message
...
I have fifteen text boxes in my userform. They have a default value of
zero. When my form loads, the first text box has the focus. I want to
highlight or select the zero so when I enter a number into the text box it
will overwrite the zero rather then put the number after the zero. I can't
figure out the code I need to highlight the zero.

The following text boxes highlight the zero automatically when I press
enter in the previous text boxes. So I just need to be able select the
first text boxes zero. Any help will be appreciated. Thanks in advance. By
the way I have excel 2003. Thanks, Mark




All times are GMT +1. The time now is 12:00 AM.

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