Calling variable from radio button in userform to a module

raghavanhr

New Member
Joined
Aug 29, 2018
Messages
5
Hi Experts,

I have a workbook with a User Form with two radio buttons (a,b), an 'OK' Command Button and a 'Cancel Command' Button.

On Sheet1("Form") I have a command button that loads the User Form.

I also have a module in VBA, where I would like to write a subroutine (called by Clicking the OK button on my User Form) that contains the value of the selected radio button. This should take a value from my User Form depending upon which of the two Radio Buttons clicked by the user, Company provided Ticket for Radio button 1 and Self Ticket for Radio BUtton 2, return this to the value to a cell address.

I am struggling to figure out how to pass and receive values between the radio button selected and would really appreciate some advice!

Thank you for reading,
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
It is not necessary to go through a module to write to a cell depending on the selected option.
VBA Code:
Private Sub CommandButton1_Click()
  If OptionButton1 = True Then Range("A3").Value = "Some data"
  If OptionButton2 = True Then Range("B3").Value = "whatever"
End Sub

But if you want it to work in a module, it is not necessary to pass the data either, you just have to read the data referring to the userform:

In userform:
VBA Code:
Private Sub CommandButton1_Click()
  Call macro_in_module
End Sub

In a module:
VBA Code:
Sub macro_in_module()
  If UserForm1.OptionButton1 = True Then Range("A3").Value = "Some data"
  If UserForm1.OptionButton2 = True Then Range("B3").Value = "whatever"
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,174
Members
452,615
Latest member
bogeys2birdies

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