+ Reply to Thread
Results 1 to 6 of 6

VBA for 3 choices of option button

  1. #1
    Forum Contributor
    Join Date
    05-01-2015
    Location
    Kent, England
    MS-Off Ver
    2013
    Posts
    148

    VBA for 3 choices of option button

    Good morning

    i have a form with 3 option buttons

    Yes
    No
    Sick/Hol

    i can code the yes no using:

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: VBA for 3 choices of option button

    You need an ElseIf there to check option 2 with the Else to catch Option 3

  3. #3
    Forum Contributor
    Join Date
    05-01-2015
    Location
    Kent, England
    MS-Off Ver
    2013
    Posts
    148

    Re: VBA for 3 choices of option button

    So like this

    IF Opt_OP1 = True Then
    Sheets("Data").Range("Data_Start").Offset(1, 3).Value = "Yes"
    ElseIf Opt_OP2 = True then
    Sheets("Data").Range("Data_Start").Offset(1, 3).Value = "No"
    Else
    Sheets("Data").Range("Data_Start").Offset(1, 3).Value = "Sick/Hol"
    End If

  4. #4
    Forum Contributor
    Join Date
    05-01-2015
    Location
    Kent, England
    MS-Off Ver
    2013
    Posts
    148

    Re: VBA for 3 choices of option button

    Quote Originally Posted by OillyBob55 View Post
    So like this

    IF Opt_OP1 = True Then
    Sheets("Data").Range("Data_Start").Offset(1, 3).Value = "Yes"
    ElseIf Opt_OP2 = True then
    Sheets("Data").Range("Data_Start").Offset(1, 3).Value = "No"
    Else
    Sheets("Data").Range("Data_Start").Offset(1, 3).Value = "Sick/Hol"
    End If
    No that didn't work that just put No in the box no matter what i had in the options

  5. #5
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: VBA for 3 choices of option button

    Sorry for brief initial answer, was on a phone.

    The only change I would make to the code you posted would be to not rely on default values but explicitly reference the property you want

    Please Login or Register  to view this content.
    There is nothing wrong with the syntax of your code as long as the controls OPT_Op1, OPT_Op2 and another exist. Post a sample of your workbook. it's probably something simple...
    Last edited by cytop; 06-17-2017 at 06:08 AM.

  6. #6
    Forum Contributor
    Join Date
    05-01-2015
    Location
    Kent, England
    MS-Off Ver
    2013
    Posts
    148

    Re: VBA for 3 choices of option button

    Quote Originally Posted by cytop View Post
    Should work...
    My mistake wrong name used works fine thank you

+ 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. Hide option buttons based on other option button
    By monfos in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-21-2016, 05:16 PM
  2. VBA code for Option Button choices on Userform
    By RedBorg in forum Excel Programming / VBA / Macros
    Replies: 28
    Last Post: 04-15-2016, 07:24 AM
  3. Allowing only 1 toggle button pushed out of 2 choices
    By ahigh17 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-30-2013, 11:51 AM
  4. Replies: 2
    Last Post: 08-15-2013, 12:25 PM
  5. Userform Option Button to Show/Hide Another Option Button on same Userform
    By R_S_6 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-26-2010, 09:44 AM
  6. Replies: 2
    Last Post: 03-27-2007, 08:30 AM
  7. [SOLVED] keep source formatting is not an option in paste option button
    By Tina in forum Excel General
    Replies: 0
    Last Post: 02-20-2006, 06:00 PM

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