JHogan0721
New Member
- Joined
- Dec 7, 2016
- Messages
- 12
I have what is probably a simple error handling issue for most of you but I can't seem to figure it out.
I have an excel userform with multiple text boxes that auto populate via a vlookup. This all works fine except for one text box I can't seem to get the error handling right for.
I need a simple error handling code to leave a textbox blank if a corresponding name cannot be found. I have included the code I am using currently to populate the box.
The box I am having issues with is labeled (rather boring) TextBox3
I am searching range "RT" to find a phone number that corresponds to the name that populates in a text box labeled "box4"
I would like "TextBox3" to remain empty if no corresponding name/number can be found in range "RT"
Any help would be greatly appreciated!
I have an excel userform with multiple text boxes that auto populate via a vlookup. This all works fine except for one text box I can't seem to get the error handling right for.
I need a simple error handling code to leave a textbox blank if a corresponding name cannot be found. I have included the code I am using currently to populate the box.
The box I am having issues with is labeled (rather boring) TextBox3
I am searching range "RT" to find a phone number that corresponds to the name that populates in a text box labeled "box4"
I would like "TextBox3" to remain empty if no corresponding name/number can be found in range "RT"
Any help would be greatly appreciated!
VBA Code:
Private Sub gobutton_click()
If WorksheetFunction.CountIf(Sheet3.Range("A:A"), Me.Box1.Value) = 0 Then
MsgBox "No Record"
Me.box2.Value = ""
Me.box3.Value = ""
Me.box4.Value = ""
Me.box5.Value = ""
Me.box6.Value = ""
Me.box7.Value = ""
Me.box8.Value = ""
Me.box9.Value = ""
Me.box10.Value = ""
Me.box11.Value = ""
Me.box12.Value = ""
Exit Sub
End If
With Me
.box2 = Application.WorksheetFunction.VLookup(CLng(Me.Box1), Sheet3.Range("master1"), 2, 0)
.box3 = Application.WorksheetFunction.VLookup(CLng(Me.Box1), Sheet3.Range("master1"), 3, 0)
.box4 = Application.WorksheetFunction.VLookup(CLng(Me.Box1), Sheet3.Range("master1"), 4, 0)
.box5 = Application.WorksheetFunction.VLookup(CLng(Me.Box1), Sheet3.Range("master1"), 5, 0)
.box6 = Application.WorksheetFunction.VLookup(CLng(Me.Box1), Sheet3.Range("master1"), 6, 0)
.box7 = Application.WorksheetFunction.VLookup(CLng(Me.Box1), Sheet3.Range("master1"), 7, 0)
.box8 = Application.WorksheetFunction.VLookup(CLng(Me.Box1), Sheet3.Range("master1"), 8, 0)
.box9 = Application.WorksheetFunction.VLookup(CLng(Me.Box1), Sheet3.Range("master1"), 9, 0)
.box10 = Application.WorksheetFunction.VLookup(CLng(Me.Box1), Sheet3.Range("master1"), 10, 0)
.box11 = Application.WorksheetFunction.VLookup(CLng(Me.Box1), Sheet3.Range("master1"), 11, 0)
.box12 = Application.WorksheetFunction.VLookup(CLng(Me.Box1), Sheet3.Range("master1"), 12, 0)
.TextBox1 = Application.WorksheetFunction.VLookup(CLng(Me.Box1), Sheet1.Range("Phonelist"), 7, 0)
.TextBox2 = Application.WorksheetFunction.VLookup((Me.box5), Sheet3.Range("DT"), 2, 0)
.TextBox4 = Application.WorksheetFunction.VLookup((Me.box5), Sheet3.Range("DT"), 3, 0)
.TextBox3 = Application.WorksheetFunction.VLookup((Me.box4), Sheet3.Range("RT"), 2, 0)
End With