ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   buttons and boxes in userform (https://www.excelbanter.com/excel-discussion-misc-queries/66026-buttons-boxes-userform.html)

Larry Sartoris

buttons and boxes in userform
 
Hi,

I was wondering if there was a way to automatically change to a different
text box after entering only one number. I know if you have multiple text
boxes then you can enter info and then hit tab to switch to the next box.
What I want to do is only enter one number into a text box and then have it
move on to the next box.

Thanks so much for any help.

Larry

Anita

buttons and boxes in userform
 
Hi Larry,

Try something like this:

Private Sub TextBox1_Change()
TextBox2.SetFocus
End Sub

For any change to the text in textbox1, textbox2 gets the focus.


Larry Sartoris

buttons and boxes in userform
 
Thanks so much for your reply and help. I just have one more question. That
worked beautifully, but what if I wanted to enter 2 numbers into the textbox?

Thanks so much!

"Anita" wrote:

Hi Larry,

Try something like this:

Private Sub TextBox1_Change()
TextBox2.SetFocus
End Sub

For any change to the text in textbox1, textbox2 gets the focus.



Anita

buttons and boxes in userform
 
You can trigger it to switch after whatever number of numbers have been
typed in, for example:

Private Sub TextBox1_Change()
If Me.TextBox1.TextLength = 1 Then Exit Sub
If Me.TextBox1.TextLength = 2 Then Me.TextBox2.SetFocus
End Sub

Will switch after two numbers have been typed in. You can use this
logic to set it to whatever number you want by setting the TextLength =
?

Anita



All times are GMT +1. The time now is 03:51 PM.

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