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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
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,224,815
Messages
6,181,136
Members
453,021
Latest member
Justyna P

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