1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Excel 2013 VBA Setfocus not working on userform after error

Discussion in 'Business Applications' started by mariaa33, Jan 15, 2015.

Thread Status:
Not open for further replies.
  1. mariaa33

    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
    
     
  2. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,608
    First Name:
    Hans
    Hi Maria,
    I think a file with the userform and the code with non-private data will make it easier to help.
     
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 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1141242

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice