L
LuisE
I have an UserForm with some TextBoxes which individuals entries I’d like to
validate before moving to the next Textbox. I want to force the user to make
a valid entry (non blank and right format) before moving to the next.
Should I place the code in the Form module??
Here is what I have for the first textbox which matches the entry to an
existing record
Sub Find_The_Name()
Set ws = ActiveSheet
Set UnitList = ws.Range("a:a")
With UnitList
Set rFound = .Find(What:=UnitNo, _
After:=Range("A1"), LookIn:=xlValues, _
Lookat:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If Not rFound Is Nothing Then
x = rFound.Address
CurrentTenant = ws.Range(x).Offset(0, 3).Text
Else
MsgBox "Couldn't find the unit number"
CurrentTenant = ""
Exit Sub
End If
End With
End Sub
Sub Find_Name01()
UnitNo = UserForm1.txtUnit01.Text
If UnitNo = "" Then
MsgBox "Make avalid entry"
Else
Call Find_The_Name
UserForm1.txtName01.Text = CurrentTenant
End If
End Sub
Thank you
validate before moving to the next Textbox. I want to force the user to make
a valid entry (non blank and right format) before moving to the next.
Should I place the code in the Form module??
Here is what I have for the first textbox which matches the entry to an
existing record
Sub Find_The_Name()
Set ws = ActiveSheet
Set UnitList = ws.Range("a:a")
With UnitList
Set rFound = .Find(What:=UnitNo, _
After:=Range("A1"), LookIn:=xlValues, _
Lookat:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If Not rFound Is Nothing Then
x = rFound.Address
CurrentTenant = ws.Range(x).Offset(0, 3).Text
Else
MsgBox "Couldn't find the unit number"
CurrentTenant = ""
Exit Sub
End If
End With
End Sub
Sub Find_Name01()
UnitNo = UserForm1.txtUnit01.Text
If UnitNo = "" Then
MsgBox "Make avalid entry"
Else
Call Find_The_Name
UserForm1.txtName01.Text = CurrentTenant
End If
End Sub
Thank you