×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

Excel Userform question: how to validate and textbox and focus back to it?

I had a problem to focus back to the same textbox after validation.

I tried setfocus on UserForm_Activate() event it worked fine. But when I use it in TextBox1_Change or Exit Event it did not work.


Also when I add the same validation in a Command_click event to validate the textbox it works when I hit the enter key after I select to command box. But not working when clicking by mouse.

Someone can help?

Following are the code:

Private Sub CommandButton1_Click()
Sheet2.Select

If TB_name.Value = "" Then

MsgBox "name is empty."
Me.Controls("TB_name").SetFocus' not working when click by mouse, but works when by enter key.


Exit Sub

End If

End Sub

Private Sub TB_name_Change()
If UserForm232.TB_name.Value = "" Then

MsgBox "Username can not be empty."

TB_nmae.SetFocus ' not working

End If

End Sub
Report