Excel 2013 VBA Setfocus not working on userform after error

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

mariaa33

Thread Starter
Joined
Aug 7, 2008
Messages
164
I have a userform that after update on Textbox1 code, checks if less than 8 characters and returns msgbox, clears textbox1 and I need it to go back to textbox 1 but continues on to textbox2 no matter what. Any help is appreciated.

Code:
Private Sub TextBox1_AfterUpdate()
Dim strResponse1 As String
Dim MasterList As Range, ListEnd As Long
ListEnd = Sheets("Master").Range("A2").End(xlDown).Row
Set MasterList1 = Sheets("Master").Range("A2:A" & ListEnd)
Set MasterList2 = Sheets("Master").Range("A2:F" & ListEnd)
strResponse1 = Left(Me.TextBox1.Value, 8)
If Len(strResponse1) > 7 Then
If Not IsError(Application.Match(strResponse1, MasterList1, 0)) Then
Loc1Lat1 = Application.WorksheetFunction.VLookup(strResponse1, MasterList2, 5, False)
Loc1Long1 = Application.WorksheetFunction.VLookup(strResponse1, MasterList2, 6, False)
MsgBox "Loc1 is in list: $ " & Loc1Lat1
MsgBox "Loc1 is in list: $ " & Loc1Long1
Else
MsgBox "Loc1 is not in list: $ " & Loc1
End If
Else
MsgBox "Value must be greater than 7"
TextBox1.Value = ""
TextBox1.SetFocus
Cancel = True
End If
 

Keebellah

Hans
Trusted Advisor
Joined
Mar 27, 2008
Messages
6,639
Hi Maria,
I think a file with the userform and the code with non-private data will make it easier to help.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top