Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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 als
two command buttons, OK and CANCEL. The idea is that each radio butto
corresponds to a different worksheet, where I intend to insert ne
rows, copy formulas etc. I'm just not sure how to take the radio butto
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
thought that by defining RC as a Public variable over in the userfor
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

--
shellshoc
-----------------------------------------------------------------------
shellshock's Profile: http://www.excelforum.com/member.php...fo&userid=2493
View this thread: http://www.excelforum.com/showthread.php?threadid=39142

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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" wrote
in message ...

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default userform output to procedure


Thanks very much, Bob. :)

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


--
shellshock
------------------------------------------------------------------------
shellshock's Profile: http://www.excelforum.com/member.php...o&userid=24935
View this thread: http://www.excelforum.com/showthread...hreadid=391428

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looping procedure calls userform; how to exit loop (via userform button)? KR Excel Programming 6 July 27th 05 12:57 PM
Quit UserForm and Procedure Maria[_7_] Excel Programming 6 September 5th 04 11:29 PM
Opening a UserForm causes a crash in the Exit procedure (Which is never called) Brent McIntyre Excel Programming 0 May 12th 04 12:37 PM
VBA question - calling Procedure from userform ajliaks[_3_] Excel Programming 2 April 14th 04 09:11 PM
Passing Userform as an argument to a procedure Howard Kaikow Excel Programming 12 October 24th 03 03:24 PM


All times are GMT +1. The time now is 08:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"