control a module from radio buttons

rhino4eva

Active Member
Joined
Apr 1, 2009
Messages
262
Office Version
  1. 2010
Platform
  1. Windows
i have just got to grips with user forms and I need a little help

I have designed a userform with 3 radio buttons to select either 1 ,2, or 3 experiments in my lab

I want to use this response to be used in a for next loop is a module so I don't have to write this 3 times over


ie for loop= 1 to (radio result) step 1
do something interesting
next loop
where (radio result) is a variable form 1 to 3 dependant on which button is pressed

I can get the "do something interesting" if its written into the code area of the userform
but not if its in a module on it own
I need to figure out how to link userform to a module

Any help would be gratefully recieved
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Try something like this for passing the Number to module outside the Userform.
The easier way is to just put the "Mynum" sub into the userform Module, this stops the need to pass the "Number" Explicitly
Code:
'Userform module#####
Option Explicit
Dim Num As Long
Private Sub CommandButton1_Click()
Call MyNum(Num) 'To call a Module, Pass num to module
End Sub
Private Sub OptionButton1_Click()
Num = 1
End Sub
Private Sub OptionButton2_Click()
Num = 2
End Sub
Private Sub OptionButton3_Click()
Num = 3
End Sub


Code:
'Module Code
Sub MyNum(n)
MsgBox n    'n = Number
End Sub
 
Last edited:
Upvote 0
Just to let you know you can put what you may think of as a Module script.
Inside a UserForm

In the UserForm Background where you see all the other scripting just choose "General" from the drop down at the top of the window and then enter your script like any other script like this:

Code:
Sub DoThis()
MsgBox "Hello"
End Sub
 
Upvote 0
That's nearly there but why doesn't the module show up when I press go ??


Try something like this for passing the Number to module outside the Userform.
The easier way is to just put the "Mynum" sub into the userform Module, this stops the need to pass the "Number" Explicitly
Code:
'Userform module#####
Option Explicit
Dim Num As Long
Private Sub CommandButton1_Click()
Call MyNum(Num) 'To call a Module, Pass num to module
End Sub
Private Sub OptionButton1_Click()
Num = 1
End Sub
Private Sub OptionButton2_Click()
Num = 2
End Sub
Private Sub OptionButton3_Click()
Num = 3
End Sub


Code:
'Module Code
Sub MyNum(n)
MsgBox n    'n = Number
End Sub
 
Upvote 0
So you put the script into the UserForm. But now your saying you want to run the module outside of the Userform also.

If this is what you want you will have to put the script into a Module also and give it a new name.
If the script is inside the Userforn you will not see the module.

But if that is what your planning you could just put a line of code in your userform like this:

Call George

If your module script is named "George"
 
Last edited:
Upvote 0
I have a question regarding linking several radio buttons together.

I have two group boxes, each containing 3 or more radio buttons. What I am trying to do is link the buttons together so that by clicking one button, you can enable/disable other buttons from being toggled, see below:


Group Box 1: Group Box 2:

- 10 - 6
- 25 - 8
- 55 - 10

This sheet is being used to configure part numbers. Basically there are certain combinations of values from Group Boxes 1 & 2 that would generate a good part number, and certain combinations that would generate a bad part number. My goal is to link these boxes if possible so that the end user can only select good numbers. I want to control this within the Excel sheet and not allow them to configure a part number that is no good.

My idea is that when the user toggles option "10" for instance from "Group Box 1", then option "6" from "Group Box 2" would either disappear, or have a strike-through in the text, or prevent the user from selecting that option. Is anything like this possible?

All of these values are being sorted into another field where the part number is sorted and generated. I could go through using conditional formatting to give a visual indicator (green or red background) based on if the part number is good or bad. . . I guess I would just prefer to not allow them to be able to even select a bad part number in the first place.

Thanks!!

Chris
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top