Hello,
I have a radio button in my VBA userform. I want to link this radio button to a Option button in Sheet1. I think you do it via the control source bu when i type
it doesnt work![]()
Sheet1!Option Button1
Hello,
I have a radio button in my VBA userform. I want to link this radio button to a Option button in Sheet1. I think you do it via the control source bu when i type
it doesnt work![]()
Sheet1!Option Button1
This is from the VBA help for ControlSource Property
ControlSource Property
Identifies the data location used to set or store the Value property of a control. The ControlSource property accepts worksheet ranges from Microsoft Excel.
Syntax
object.ControlSource [= String]
The ControlSource property syntax has these parts:
Part Description
object Required. A valid object.
String Optional. Specifies the worksheet cell linked to the Value property of a control.
Remarks
The ControlSource property identifies a cell or field; it does not contain the data stored in the cell or field. If you change the Value of the control, the change is automatically reflected in the linked cell or field. Similarly, if you change the value of the linked cell or field, the change is automatically reflected in the Value of the control.
You cannot specify another control for the ControlSource. Doing so causes an error.
The default value for ControlSource is an empty string. If ControlSource contains a value other than an empty string, it identifies a linked cell or field. The contents of that cell or field are automatically copied to the Value property when the control is loaded.
Set both option buttons (userform and worksheet) control sources to the same cell address e.g. Sheet1!A1
Surround your VBA code with CODE tags e.g.;
[CODE]your VBA code here[/CODE]
The # button in the forum editor will apply CODE tags around your selected text.
Hi buwa84,
Thank you AlphaFrog for introducing me to the ControlSource Property
The control source property does not apply to a single option button in a Spreadsheet, but to the group: http://msdn.microsoft.com/en-us/libr...ice.15%29.aspx
Having said that I was unsuccessful linking any Worksheet 'Active X' control using ControlSource.
However I was successful using ControlSource with UserForm Option Buttons.
To link UserForm Option Buttons to a cell (please note this is bi-directional):
Lewis![]()
Sub UseControlSourceForUserFormAndActiveXControls() UserForm1.Show False 'This links 'Active X' Option buttons to Cells on the Spreadsheet 'The value TRUE Or FALSE is displayed in the Cell (this is bi-directional) 'If the value in the spreadsheet cell is changed, then the UserForm option buttons will change state) UserForm1.OptionButton1.ControlSource = "Sheet1!A33" UserForm1.OptionButton2.ControlSource = "Sheet1!A34" UserForm1.OptionButton3.ControlSource = "Sheet1!A35" End Sub
I was successful in making UserForm Option Buttons control Forms Options Buttons and 'Active X' Option Buttons on the worksheet.
In the UserForm code module:
Lewis![]()
Option Explicit Private Sub OptionButton1_Click() 'This code is for Forms Option Button 1 in a group 'The forms option buttons are linked to cell 'A22' ' 'The forms option buttons are linked by: 'a. Right clicking on a forms control 'b. Select 'Format Control' 'c. Type in the 'Cell Link' (e.g. A22) 'NOTE: All Forms Controls in a group are linked to the same cell (displays a number 1, 2, 3) Sheets("Sheet1").Range("A22") = 1 'This code is for Active X Option Button named 'OptionButton1' 'The 'Active X' option buttons can be linked by: 'a. Right clicking on an option button while in 'Design Mode' 'b. Select Properties 'c. Select a 'GroupName' (e.g. 'GroupX' and a 'Linked Cell' (e.g. 'K16') 'NOTE: 'Active X' Controls in a group are linked to DIFFERENT CELLS (displays TRUE or FALSE) Sheets("Sheet1").OptionButton1.Value = True End Sub Private Sub OptionButton2_Click() 'This code is for Forms Option Button 2 in a group 'The forms option buttons are linked to cell 'A22' Sheets("Sheet1").Range("A22") = 2 'This code is for Active X Option Button named 'OptionButton2' Sheets("Sheet1").OptionButton2.Value = True End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks