Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: InputBox

  1. #1
    Board Regular
    Join Date
    Apr 2002
    Location
    Pittsburgh, PA
    Posts
    354
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I have the following code:

    On Error GoTo Canceled
    NewWONumber = InputBox("Enter the new work order number", "Work Order Number")
    On Error GoTo Canceled
    NewClient = InputBox("Enter the new client / description", "Description")
    On Error GoTo Canceled
    NewLocation = InputBox("Enter the new location", "Location")

    How can I make it so if the user clicks Cancel on the InputBox, the sub is ended?
    Thanks in advance,
    Patrick

  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Bogota, Colombia
    Posts
    11,959
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Sub T()
    Dim ans As Variant

    ans = InputBox("Testing", "Testing")

    If ans = "" Then
    MsgBox "Pressed Cancel, exiting now"
    Exit Sub
    Else
    MsgBox ans
    End If
    End Sub


    Something like this ?
    Regards,

    Juan Pablo González
    http://www.juanpg.com

  3. #3
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi Patrick
    I'd also suggest looking at the Application
    inputbox method, it gives you options to
    limit the user input to formulas, numbers,
    text, logical value (True or False), cell reference, as a Range object etc.



    Kind Regards,
    Ivan F Moala From the City of Sails

  4. #4
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Bogota, Colombia
    Posts
    11,959
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-04-12 13:54, Ivan F Moala wrote:
    Hi Patrick
    I'd also suggest looking at the Application
    inputbox method, it gives you options to
    limit the user input to formulas, numbers,
    text, logical value (True or False), cell reference, as a Range object etc.
    Sticking to Ivan's advice, when the user presses Cancel, the Application.InputBox method returns False, instead of "" (Which I prefer !)
    Regards,

    Juan Pablo González
    http://www.juanpg.com

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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