+ Reply to Thread
Results 1 to 2 of 2

Code error with input box

  1. #1
    Registered User
    Join Date
    10-24-2005
    Posts
    55

    Code error with input box

    Hi Guys

    Here is my code 4 a print box (how many copies would you like)

    Private Sub CommandButton1_Click()
    Dim ws As Worksheet
    Dim no_of_copies As Integer

    Select Case True
    Case OptionButton1
    Set ws = Sheets("verticalordersheet")
    Case OptionButton2
    Set ws = Sheets("verticalvanesordersheet")
    End Select

    no_of_copies = Application.InputBox("How many copies do you wish to print?", , 1)

    ws.PrintOut copies:=no_of_copies, Collate:=True


    Close

    End Sub

    But i get 2 errors

    1. is "Run-time error 91" This happens when you do not select a option button

    2. is "Run-time error 1004" This happens when you press the cancel button

    Can you help

    Thanks

  2. #2
    Tom Ogilvy
    Guest

    Re: Code error with input box

    Private Sub CommandButton1_Click()
    Dim ws As Worksheet
    Dim no_of_copies As Integer

    Select Case True
    Case OptionButton1.Value
    Set ws = Sheets("verticalordersheet")
    Case OptionButton2.Value
    Set ws = Sheets("verticalvanesordersheet")
    Case Else
    Exit sub
    End Select

    no_of_copies = Application.InputBox("How many copies do you wish to
    print?", , 1)
    if no_of_Copies = 0 then exit sub
    ws.PrintOut copies:=no_of_copies, Collate:=True

    ' not sure what close is supposed to be
    Close

    End Sub

    --
    Regards,
    Tom Ogilvy


    "raw" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Hi Guys
    >
    > Here is my code 4 a print box (how many copies would you like)
    >
    > Private Sub CommandButton1_Click()
    > Dim ws As Worksheet
    > Dim no_of_copies As Integer
    >
    > Select Case True
    > Case OptionButton1
    > Set ws = Sheets("verticalordersheet")
    > Case OptionButton2
    > Set ws = Sheets("verticalvanesordersheet")
    > End Select
    >
    > no_of_copies = Application.InputBox("How many copies do you wish to
    > print?", , 1)
    >
    > ws.PrintOut copies:=no_of_copies, Collate:=True
    >
    >
    > Close
    >
    > End Sub
    >
    > But i get 2 errors
    >
    > 1. is "Run-time error 91" This happens when you do not select a option
    > button
    >
    > 2. is "Run-time error 1004" This happens when you press the cancel
    > button
    >
    > Can you help
    >
    > Thanks
    >
    >
    > --
    > raw
    > ------------------------------------------------------------------------
    > raw's Profile:

    http://www.excelforum.com/member.php...o&userid=28312
    > View this thread: http://www.excelforum.com/showthread...hreadid=478987
    >




+ 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