+ Reply to Thread
Results 1 to 3 of 3

userform output to procedure

  1. #1
    Registered User
    Join Date
    07-05-2005
    Posts
    24

    userform output to procedure

    I have a procedure, where I call a userform:

    Sub NewProcedure()
    UserForm1.Show

    The userform pops up, and I have a series of radio buttons, and also two command buttons, OK and CANCEL. The idea is that each radio button corresponds to a different worksheet, where I intend to insert new rows, copy formulas etc. I'm just not sure how to take the radio button user input and output it to my procedure.

    My UserForm1 code looks like this:

    Public RC As Worksheet
    Private ws As Worksheet

    Private Sub OptionButton1_Click()
    Set ws = Worksheets("Sheet1")
    End Sub

    Private Sub OptionButton2_Click()
    Set ws = Worksheets("Sheet2")
    End Sub

    Private Sub OptionButton3_Click()
    Set ws = Worksheets("Sheet3")
    End Sub

    Private Sub OK_Click()
    Set RC = ws
    Hide
    End Sub

    Private Sub CANCEL_Click()
    Unload Me
    End Sub

    And then, back in the Sub procedure, I have:

    Worksheets(RC).Activate

    This doesn't work because it says the variable RC is not defined. But I thought that by defining RC as a Public variable over in the userform code, that RC would be recognized anywhere in the Project.

    However, if I put RC into quotations, then I get a "Run-time error 9: subscript out of range".

    What am I doing wrong?

  2. #2
    Bob Phillips
    Guest

    Re: userform output to procedure

    Private Sub CANCEL_Click()
    Me.Hide
    End Sub

    and

    Userform1.RC.Activate

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "shellshock" <[email protected]> wrote
    in message news:[email protected]...
    >
    > I have a procedure, where I call a userform:
    >
    > Sub NewProcedure()
    > UserForm1.Show
    >
    > The userform pops up, and I have a series of radio buttons, and also
    > two command buttons, OK and CANCEL. The idea is that each radio button
    > corresponds to a different worksheet, where I intend to insert new
    > rows, copy formulas etc. I'm just not sure how to take the radio button
    > user input and output it to my procedure.
    >
    > My UserForm1 code looks like this:
    >
    > Public RC As Worksheet
    > Private ws As Worksheet
    >
    > Private Sub OptionButton1_Click()
    > Set ws = Worksheets("Sheet1")
    > End Sub
    >
    > Private Sub OptionButton2_Click()
    > Set ws = Worksheets("Sheet2")
    > End Sub
    >
    > Private Sub OptionButton3_Click()
    > Set ws = Worksheets("Sheet3")
    > End Sub
    >
    > Private Sub OK_Click()
    > Set RC = ws
    > Hide
    > End Sub
    >
    > Private Sub CANCEL_Click()
    > Unload Me
    > End Sub
    >
    > And then, back in the Sub procedure, I have:
    >
    > Worksheets(RC).Activate
    >
    > This doesn't work because it says the variable RC is not defined. But I
    > thought that by defining RC as a Public variable over in the userform
    > code, that RC would be recognized anywhere in the Project.
    >
    > However, if I put RC into quotations, then I get a "Run-time error 9:
    > subscript out of range".
    >
    > What am I doing wrong?
    >
    >
    > --
    > shellshock
    > ------------------------------------------------------------------------
    > shellshock's Profile:

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




  3. #3
    Registered User
    Join Date
    07-05-2005
    Posts
    24
    Thanks very much, Bob.

    I always screw up my syntax, since I'm still quite new to VBA and programming in general.

+ 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