+ Reply to Thread
Results 1 to 12 of 12

Need VBA code to hide cells if radio button in another cell is chosen

  1. #1
    Registered User
    Join Date
    03-20-2011
    Location
    Northern California (The Better Half)
    MS-Off Ver
    2010
    Posts
    6

    Need VBA code to hide cells if radio button in another cell is chosen

    One line of a form has one radio button marked "PARTS DUE DATE". Next cell is a date which is provided by a drop-down calendar. Another cell on the line has another radio button marked "SERVICE DUE DATE" with another cell that is populated by another drop-down calendar.

    My question is....how do I hide one date cell when the other radio button is chosen? I don't need a SERVICE DUE DATE if it is a parts order and vice versa. Can anyone help me? I'm a novice at VBA...I know enough to be vewwy, vewwy dangewous.

    sqearly
    Last edited by sqearly; 03-31-2011 at 12:58 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Need VBA code to hide cells if radio button in another cell is chosen

    Forms Toolbar radio buttons - make sure both buttons are linked to the same cell.
    (right-click > Format Control > Control tab > Linked Cell)

    Control Toolbox Toolbar radio buttons - make sure these buttons are in the same GroupName.
    (Right-click > Properties > GroupName)


    Once these are set properly, you cannot select more than 1 button in the "group". You will have to add VBA to the radio buttons themselves if you wish to hide/unhide specific columns, too. If you need specific help on that, post your workbook.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    03-20-2011
    Location
    Northern California (The Better Half)
    MS-Off Ver
    2010
    Posts
    6

    Re: Need VBA code to hide cells if radio button in another cell is chosen

    Thanks for the reply Jerry. I have grouped these two radio buttons so they act independently of all the other radio buttons on the form. I have attached a copy of the form. On the line that has "PARTS DUE DATE" and "SERVICE DUE DATE", I'd like to have just one pull down calendar on the right side of the form that populates the cell next to the radio button that has been chosen on that particular line.
    Attached Files Attached Files

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Need VBA code to hide cells if radio button in another cell is chosen

    Sorry to be a bother, but the converter I use to open 2007 files in my 2003 program doesn't leave your vba objects functional.

    Can you save your workbook as an .xls file to see if that does the job?

    Also, please indicate more precisely cells/objects you're asking for assistance on, that last sentence above left me scratching my head.

  5. #5
    Registered User
    Join Date
    03-20-2011
    Location
    Northern California (The Better Half)
    MS-Off Ver
    2010
    Posts
    6

    Re: Need VBA code to hide cells if radio button in another cell is chosen

    Here is the file in a 97-2003 version Jerry. Scenario: I hit the radio button in cells A16-C16 and choose a date from the pull down calendar in cell E16; it will then populate cell D16 with the date. When I do this, I would want cell I16 to be hidden because I don't need a SUPPLIER DUE DATE if it is a parts order and vice versa.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Need VBA code to hide cells if radio button in another cell is chosen

    Perfect.

    In the DatePicker1 Sheet module, find these two events and replace them, or add them if they aren't there:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    03-20-2011
    Location
    Northern California (The Better Half)
    MS-Off Ver
    2010
    Posts
    6

    Re: Need VBA code to hide cells if radio button in another cell is chosen

    Does it matter if this new code goes before or after the existing datepicker code?

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Need VBA code to hide cells if radio button in another cell is chosen

    Each of these subs is independent. As long as they're in the correct sheet module, it doesn't matter what order they're in.

  9. #9
    Registered User
    Join Date
    03-20-2011
    Location
    Northern California (The Better Half)
    MS-Off Ver
    2010
    Posts
    6

    Re: Need VBA code to hide cells if radio button in another cell is chosen

    Hey Jerry...I put in the code and Excel gave me an error message when I attempted to close the VB code window. The error code is:

    Compile error:
    Ambiguous Name Detected: OptionButton6_Click

    I got the same error message for the OptionButton7 code too.

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Need VBA code to hide cells if radio button in another cell is chosen

    That means you added the code without looking to find the "existing" OptionButton6_click macro, that message means you are trying to save a module with more than one macro with the same name. My code was to replace your existing ones.

    Quote Originally Posted by from post #6
    In the DatePicker1 Sheet module, find these two events and replace them, or add them if they aren't there:

  11. #11
    Registered User
    Join Date
    03-20-2011
    Location
    Northern California (The Better Half)
    MS-Off Ver
    2010
    Posts
    6

    Re: Need VBA code to hide cells if radio button in another cell is chosen

    Right you are Jerry. I replaced the existing code and it worked. I changed the "I" and the "A" to a "D" in the OptionButton6 code but after I did that it worked exactly like I wanted it to. Your code should allow me to write a macro for another radio button scenario I have in the form.

    Thanks for your help Jerry. Makes me want to learn even more about VBA.

  12. #12
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Need VBA code to hide cells if radio button in another cell is chosen

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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