+ Reply to Thread
Results 1 to 2 of 2

option botton assign 1 or 0 to a cell based on selection

Hybrid View

hjk option botton assign 1 or 0... 03-16-2007, 03:07 PM
jasoncw Are the option buttons from... 03-16-2007, 03:45 PM
  1. #1
    Registered User
    Join Date
    03-16-2007
    Posts
    2

    option botton assign 1 or 0 to a cell based on selection

    i have a quick excel question that involves macro.

    basically, what i need to do is this.

    i have option buttons and when one out of three buttons is clicked, it
    needs to put the value "1" in the cell right behind the selected
    option button and "0" into each cell behind other option buttons.

    do you have any suggestions for the macro?

    much thanks in advance,

    hyejin

  2. #2
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Are the option buttons from the Toolbox toolbar or the Forms toolbar? If they are from the Toolbox toolbar, you can use the Change event handler procedure to to this:
    Private Sub OptionButton1_Change()
        If OptionButton1 = True Then Range("A1") = 1 Else Range("A1") = 0
    End Sub
    
    Private Sub OptionButton2_Change()
        If OptionButton2 = True Then Range("A2") = 1 Else Range("A2") = 0
    End Sub
    
    Private Sub OptionButton3_Change()
        If OptionButton3 = True Then Range("A3") = 1 Else Range("A3") = 0
    End Sub
    If they are from the Forms toolbar, perhaps you might want to use the built-in feature of the option buttons. If none are selected, the value is 0; if the first button is selected, the value is 1; if the second button is selected, the value is 2; etc.

    All you would have to do for this to work is include the Linked Cell as one of the cells on the sheet. It will be the same linked cell for all option buttons.

    HTH

    Jason

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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