Hi folks. If data in textbox is not entered correctly (or not at all) I want the sub to end/exit & set focus to the textbox. Below is my code for what i am trying to do -
[code]If Not IsNumeric(Me.txtUSNo.Text) Then
MsgBox "Type a value please"
Exit Sub
Else
If Not Val(txtUSNo.Text) > 55 And Val(txtUSNo.Text) < 20589 Then
MsgBox "Enter Valid amount between 50 to 20600", vbOKOnly
txtUSNo.Text = ""
txtUSNo.SetFocus
Exit Sub
Else 'Ensure date is entered - needs more work
If txtDateAchvd.Text = "" Then
MsgBox "Please enter valid Date Format", vbOKOnly
txtDateAchvd.Text = ""
txtDateAchvd.SetFocus
Exit Sub
Else
'Workbooks("06US_StudentVBA test.xls").Select
ActiveWorkbook.Sheets("US Prgss").Select 'Select
Range("S6:CZ6").Select
Selection.Find(What:=USNo, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = DateAchvd
'Places USno on NatCert sheet
Add_US
End If
End If
End If [/code]
I hope I have made myself clear.
Cheers
Don't take life too seriously as you never get out alive anyway!
Comments
:
:
:
: [code]If Not IsNumeric(Me.txtUSNo.Text) Then
: MsgBox "Type a value please"
:
: Exit Sub
: Else
: If Not Val(txtUSNo.Text) > 55 And Val(txtUSNo.Text) < 20589 Then
: MsgBox "Enter Valid amount between 50 to 20600", vbOKOnly
: txtUSNo.Text = ""
: txtUSNo.SetFocus
:
: Exit Sub
: Else 'Ensure date is entered - needs more work
: If txtDateAchvd.Text = "" Then
: MsgBox "Please enter valid Date Format", vbOKOnly
: txtDateAchvd.Text = ""
: txtDateAchvd.SetFocus
: Exit Sub
: Else
: 'Workbooks("06US_StudentVBA test.xls").Select
: ActiveWorkbook.Sheets("US Prgss").Select 'Select
: Range("S6:CZ6").Select
: Selection.Find(What:=USNo, After:=ActiveCell, LookIn:=xlFormulas, _
: LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
: MatchCase:=False).Activate
: ActiveCell.Offset(1, 0).Select
: ActiveCell.FormulaR1C1 = DateAchvd
:
: 'Places USno on NatCert sheet
: Add_US
: End If
: End If
: End If [/code]
:
:
: I hope I have made myself clear.
:
: Cheers
:
:
: Don't take life too seriously as you never get out alive anyway!
:
Hi,
and where's your problem? I've tried your code and it works fine..
[blue][b][italic][size=4]P[/size]avlin [size=4]II[/italic][/size][/b][/blue]
[purple]Don't take life too seriously anyway you won't escape alive from it![/purple]