Results 1 to 12 of 12

Help with a VBA condition

Threaded View

  1. #1
    Registered User
    Join Date
    06-28-2015
    Location
    England
    MS-Off Ver
    2013
    Posts
    39

    Help with a VBA condition

    Hi

    I have this VBA code but I would like it to not produce an error message if the TextBox is left blank.

    Private Sub TextBox5_Exit(ByVal Cancel As MSForms.ReturnBoolean)
        Dim strCode
        Dim sOut As String, i As Integer
        strCode = Replace(UCase(TextBox5.Value), " ", "")
        If Not (strCode Like "[A-Z][A-Z]######[A-D]") Then
            MsgBox "Please enter NINO in the correct format", vbCritical
            Cancel = True
        
        Else
            For i = 1 To 9
                Select Case i
                    Case 3, 5, 7, 9
                        sOut = sOut & " " & Mid(strCode, i, 1)
                    Case Else
                        sOut = sOut & Mid(strCode, i, 1)
                End Select
            Next i
                
        End If
        TextBox5.Value = sOut
    
    End Sub
    Thanks

    Don
    Last edited by DonJuan85; 06-28-2015 at 04:29 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 7
    Last Post: 06-01-2015, 06:05 PM
  2. Condition formatting of multiple condition formatted cells
    By merrin84 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 02-22-2015, 05:08 PM
  3. [SOLVED] Help for if condition formula result only either hit or miss from mulitple condition
    By breadwinner in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-09-2013, 07:29 AM
  4. Replies: 6
    Last Post: 05-06-2010, 10:06 PM
  5. multi condition format? lookup and date condition valid for.
    By D_Rennie in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-13-2009, 11:37 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1