Results 1 to 6 of 6

Thread: vba coding (97)

  1. #1
    Star Lounger
    Join Date
    Apr 2001
    Location
    SOUTH AFRICA
    Posts
    74
    Thanks
    0
    Thanked 0 Times in 0 Posts

    vba coding (97)

    Hi All

    Please help me with the vba coding: I have an input box where the user must input a figure. How do I ignore the rest of the coding behind the command button when the user press cancel instead of enter the figure?

    Cheers and thanks for your help.

  2. #2
    2 Star Lounger
    Join Date
    Feb 2001
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: vba coding (97)

    strAnswer = InputBox("Please enter a figure", "Enter a Figure")
    If strAnswer = " " _
    Then
    Exit Sub
    End If

    ...or sumthin' like that...

    The inputbox returns an empty string if the user presses cancel.

    You probably want use IsNumeric to check if the answer is a number. I'm assuming when you say "figure" you mean a number.

  3. #3
    2 Star Lounger
    Join Date
    Feb 2001
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: vba coding (97)

    You might check out this thread.

    <A target="_blank" HREF=http://www.wopr.com/cgi-bin/w3t/showflat.pl?Cat=&Board=acc&Number=77584&page=&view =&sb=&o=&vc=1>http://www.wopr.com/cgi-bin/w3t/showflat.p...ew=&sb=&o=&vc=1</A>

  4. #4
    Star Lounger
    Join Date
    Apr 2001
    Location
    SOUTH AFRICA
    Posts
    74
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: vba coding (97)

    Thanks for all the help Mike

    Cheers

  5. #5
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: vba coding (97)

    In Excel, you also can use the InputBox method. It has one additional parameter, Type, so that you can force your users to enter a particular type of data: a number, text, or even a range. Checking for Cancel is a little tricky, Excel returns False, but VBA will convert lots or stuff into a False. Here is how I would get only a numerical response from the user:
    <pre>Option Explicit
    Sub Macro1()
    Dim rsp As Variant
    rsp = Application.InputBox("Enter a number", , 10, , , , , 1)
    If TypeName(rsp) = "Boolean" Then Exit Sub
    MsgBox "You're #" & rsp
    End Sub
    </pre>

    Notice that I never bothered to check for False: the only time Excel will return a Boolean is when the Cancel button is pressed. Be sure to include the Application before InputBox; otherwise you'll get a syntax error.

    Excel's InputBox method is most useful to get the user to select a Range. Hope this helps! --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  6. #6
    Star Lounger
    Join Date
    Apr 2001
    Location
    SOUTH AFRICA
    Posts
    74
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: vba coding (97)

    Thanks a lot for the useful information, Sam

Posting Permissions

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