+ Reply to Thread
Results 1 to 2 of 2

Looping sub not detecting user cancel from inputbox

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-14-2012
    Location
    Derby, England
    MS-Off Ver
    Excel 2010
    Posts
    257

    Looping sub not detecting user cancel from inputbox

    Hi All, Can someone help with my sub. I'm trying to get it to do the fllowing. IF the user presses cancel the sub exits, if they enter nothing it loops until they do and if they do enter something then it runs another sub to check what they have entered is valid. I've tried userName = False but it gives type mismatch. I've tried userName = "" but then it just keeps looping as I need <>"" to do something else. Can anyone help. Regards, John

    Sub Use()
        Dim userName As Variant
        Dim nameOk As Boolean
        Dim username2 As String
        
    
            userName = Application.Proper(InputBox("Enter Name", "Name"))
            username2 = userName
            If userName = "" Then
            Exit Sub
            ElseIf (userName <> "") Then nameOk = ValidateName(username2)
            Else: MsgBox "ok"
            End If
    '    Loop While (userName <> "")
    End Sub

  2. #2
    Forum Contributor
    Join Date
    08-14-2012
    Location
    Derby, England
    MS-Off Ver
    Excel 2010
    Posts
    257

    Re: Looping sub not detecting user cancel from inputbox

    Ok so I sorted it by doing:

    userName = Application.Proper(Application.InputBox("Enter Name", "Name"))
    Then it will detect a "False"

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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