![]() |
VBA - using Goto - Please Help!
Hi,
I need to check data, and if it is wrong, go back to the text box, an inpt data again. I am trying something like this: In comand button ok: If (PercentTB.Value < 0) Or (PercentTB.Value 100) Then PercentTB = "" MsgBox "Value must be between 0.00% - 100.0%" GoSub PercentTB End If Where PercentTB have this sub: Private Sub PercentTB_KeyPress(ByVal KeyAscii A MSForms.ReturnInteger) If ((KeyAscii < Asc("0")) Or (KeyAscii Asc("9"))) Then KeyAscii = 0 End If End Sub and I get ERROR, Label not defined in line "GoSub PercentTB" I also need text box "PercentTB" looking like XX.X% Thanks -- Message posted from http://www.ExcelForum.com |
VBA - using Goto - Please Help!
Put your conditions in the Exit Event
Private Sub PercentTB_Exit(ByVal Cancel As MSForms.ReturnBoolean) PercentTB.Text = Format(csng(PercentTB.Text),"#0.#%) if conditions not met then Cancel = True End if End Sub Cancel set to true cancels the exit from the box. -- Regards, Tom Ogilvy "ajliaks " wrote in message ... Hi, I need to check data, and if it is wrong, go back to the text box, and inpt data again. I am trying something like this: In comand button ok: If (PercentTB.Value < 0) Or (PercentTB.Value 100) Then PercentTB = "" MsgBox "Value must be between 0.00% - 100.0%" GoSub PercentTB End If Where PercentTB have this sub: Private Sub PercentTB_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) If ((KeyAscii < Asc("0")) Or (KeyAscii Asc("9"))) Then KeyAscii = 0 End If End Sub and I get ERROR, Label not defined in line "GoSub PercentTB" I also need text box "PercentTB" looking like XX.X% Thanks. --- Message posted from http://www.ExcelForum.com/ |
VBA - using Goto - Please Help!
You could test the value and then reset the focus to the textbox. Something
like With PercentTB If (.Value < 0) Or (.Value 100) Then MsgBox "Value must be between 0.00% - 100.0%" .SelStart = 0 .SelLength = Len(.Text) .SetFocus End If End With -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "ajliaks " wrote in message ... Hi, I need to check data, and if it is wrong, go back to the text box, and inpt data again. I am trying something like this: In comand button ok: If (PercentTB.Value < 0) Or (PercentTB.Value 100) Then PercentTB = "" MsgBox "Value must be between 0.00% - 100.0%" GoSub PercentTB End If Where PercentTB have this sub: Private Sub PercentTB_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) If ((KeyAscii < Asc("0")) Or (KeyAscii Asc("9"))) Then KeyAscii = 0 End If End Sub and I get ERROR, Label not defined in line "GoSub PercentTB" I also need text box "PercentTB" looking like XX.X% Thanks. --- Message posted from http://www.ExcelForum.com/ |
All times are GMT +1. The time now is 03:04 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com