Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Creating a form with option buttons

I need to create a user form that has 4 option buttons and an ok button
to close the form. i have gotten the ok button to work fine with

Private Sub OK_Click()
Unload UserForm1
End Sub

but now i want to make the 4 option buttons set a variable to either
1,2,3, or 4. How can I do this? Do i need code in the private sub for
the button or in my main code? Thanks!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Creating a form with option buttons

Hi Jon,

In a standard module, before any code, paste:

Public myVar As Long

Then, in the userform module, try:

'=============
Private Sub OptionButton1_Click()
myVar = 1
End Sub

Private Sub OptionButton2_Click()
myVar = 2
End Sub

Private Sub OptionButton3_Click()
myVar = 3
End Sub

Private Sub OptionButton4_Click()
myVar = 4
End Sub
'<<=============

If you wish to reset the myVar variable each time that the form is opened,
try:

'=============
Private Sub UserForm_Initialize()
myVar = 0
End Sub
'<<=============

This should be pasted in the userform module.


---
Regards,
Norman


"Jon" wrote in message
oups.com...
I need to create a user form that has 4 option buttons and an ok button
to close the form. i have gotten the ok button to work fine with

Private Sub OK_Click()
Unload UserForm1
End Sub

but now i want to make the 4 option buttons set a variable to either
1,2,3, or 4. How can I do this? Do i need code in the private sub for
the button or in my main code? Thanks!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Creating a form with option buttons

Without knowing more, possibly:

Public v as Integer
Private Sub OptionButton1_Click()
v = 1
End Sub

Private Sub OptionButton2_Click()
v = 2
End Sub

Private Sub OptionButton3_Click()
v = 3
End Sub

Private Sub OptionButton4_Click()
v = 4
End Sub

--
Regards,
Tom Ogilvy


"Jon" wrote in message
oups.com...
I need to create a user form that has 4 option buttons and an ok button
to close the form. i have gotten the ok button to work fine with

Private Sub OK_Click()
Unload UserForm1
End Sub

but now i want to make the 4 option buttons set a variable to either
1,2,3, or 4. How can I do this? Do i need code in the private sub for
the button or in my main code? Thanks!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Creating a form with option buttons

Thanks. My error was that I did not define the variable as public.

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
form option buttons - how can I make them accessible? lynn Excel Discussion (Misc queries) 1 February 10th 10 02:59 PM
Option Buttons in a Form Idaho Word Man Excel Discussion (Misc queries) 7 April 21st 08 09:58 PM
option buttons in a form raw[_11_] Excel Programming 0 November 11th 05 10:05 PM
User Form Option & Command Buttons Information Hog[_2_] Excel Programming 1 August 19th 05 10:00 PM
2 sets of option buttons on one user form? Pal Excel Programming 3 April 28th 04 02:45 PM


All times are GMT +1. The time now is 09:49 PM.

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

About Us

"It's about Microsoft Excel"