+ Reply to Thread
Results 1 to 4 of 4

Linking a VBA Form Radio Button to a Option Button

Hybrid View

buwa84 Linking a VBA Form Radio... 06-05-2014, 11:19 AM
AlphaFrog Re: Linking a VBA Form Radio... 06-05-2014, 11:54 AM
LJMetzger Re: Linking a VBA Form Radio... 06-05-2014, 01:41 PM
LJMetzger Re: Linking a VBA Form Radio... 06-05-2014, 01:46 PM
  1. #1
    Registered User
    Join Date
    05-09-2013
    Location
    Toronto
    MS-Off Ver
    Excel 2003
    Posts
    56

    Linking a VBA Form Radio Button to a Option Button

    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

    Sheet1!Option Button1
    it doesnt work

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Linking a VBA Form Radio Button to a Option Button

    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.

  3. #3
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Linking a VBA Form Radio Button to a Option Button

    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):
    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
    Lewis

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Linking a VBA Form Radio Button to a Option Button

    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:
    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
    Lewis

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Linking Option Button(Control Form) to Shapes
    By Heva in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-17-2013, 05:24 AM
  2. Linking Option Button(Control Form) to Shapes
    By Heva in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-16-2013, 03:37 AM
  3. Hide a picture button placed in all sheets using a option button (form control)
    By lagaranch in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-26-2012, 10:33 AM
  4. VBA User Form - Linking Close Button and Cancel Button
    By nivassrii in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-26-2011, 07:05 AM
  5. Radio or option button
    By Susan in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-14-2006, 11:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1