+ Reply to Thread
Results 1 to 5 of 5

Hide/Display radio buttons

  1. #1
    Registered User
    Join Date
    07-09-2014
    Location
    Lisbon
    MS-Off Ver
    Microsoft Office 365 ProPlus Version 1708 (build 8431.2153)
    Posts
    62

    Hide/Display radio buttons

    Hi

    Is it possible to, based on a cell value, display or hide a correspondent radio button?

    I'm using an excel file as a search tool. That search will return values on cells from E5 to E20. It can be 1 result, filling one cell or multiple results, filling the equal amount of cells.
    I've added radio buttons to copy that specific cell value. What I'm curious about if is it possible to hide the radio button if the correspondent cell is empty. For example, if only 3 results are found, only 3 radio buttons appear (instead of all 15).

    Please, see the attachment.
    Besides the dummy data, everything else is real.
    You can search for "1", "2", "3", etc. When searching for "1", for example, only one line is fulfilled and my intention is to hide the radio buttons that correspond to no results.
    So: If B9 is empty OptionButton3 is hidden.

    Thanks in advance.
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    06-09-2011
    Location
    Germany
    MS-Off Ver
    Excel 2016
    Posts
    194

    Re: Hide/Display radio buttons

    Hi no_Fate,

    you made it extra complex to help you for various reasons :
    1. Your worksheet is protected and there was no indication of the password in your code (fortunately the old "7-ZIP" trick worked)
    2. There is no logic behind the names of the option buttons and their positions. For option Buttons 2 to Button 8 one could simply add "6" to button number to find the relevant row, but this would not work for buttons 13 and 14.

    Therefore the macro looks slightly more complicated. As it uses the "worksheet change event" you will need to regard where to place it in VBE:

    The macro must not be placed in a "normal" module but in the code module of the "Reference Guide" Sheet object. To create a worksheet Change event: use the Visual Basic Editor -> in the Project Explorer, double click on the appropriate sheet (under 'Microsoft Excel Objects' which is under the VBAProject/name of your workbook) -> in the Code window, select "Worksheet" from the left-side "General" drop-down menu and then select "Change" from the right-side "Declarations" drop-down menu. enter the below macro into the "Worksheet_Change" macro. Don't forget to adjust the Password!

    Please Login or Register  to view this content.
    Let me know if it works as expected!

    Theo
    Remember To Do the Following....
    1. Upload sample files
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.

  3. #3
    Registered User
    Join Date
    07-09-2014
    Location
    Lisbon
    MS-Off Ver
    Microsoft Office 365 ProPlus Version 1708 (build 8431.2153)
    Posts
    62

    Re: Hide/Display radio buttons

    Hi Fettertiger

    I'm sorry for all that
    The sheet is protected to unable other cells to be selected... I just forgot to tell you the password, which is "pass".
    The complicated part is there because, as you can imagine, I'm not an expert on VBA so I just place there what seams to make sense... sometimes wrong, I believe

    This is working perfectly! Thank you so much!
    I just added a "Sheet1.Protect" to you code, changed the buttons names and compiled all the copy macros.

    Reference Guide.xlsm

    Can I just ask one more thing?
    When I click a radio button the text is copied and I can paste it anywhere except another excel file. Somehow the clipboard is "cleaned".
    Is there something (wrong) in my modules that is causing this?

    Once again, thanks a lot!

  4. #4
    Forum Contributor
    Join Date
    06-09-2011
    Location
    Germany
    MS-Off Ver
    Excel 2016
    Posts
    194

    Re: Hide/Display radio buttons

    Hi no_Fate,

    the reason for the strange behavior is that the cells which are copied by your macro are outside of the accesible area. Rather than using the "copy" command you could add the following function to add text to clipboard:

    Please Login or Register  to view this content.
    The option Button Subs would need to be adjusted accordingly:
    Please Login or Register  to view this content.
    Please note that you forgot to add the "PW" after the protect command. While the sheet is still protected after the macro runs for the first time, the password will no longer be required. I recommend to change Sheet1.Protect to Sheet1.Protect PW

    Let me know if this solves the issue

    Theo

  5. #5
    Registered User
    Join Date
    07-09-2014
    Location
    Lisbon
    MS-Off Ver
    Microsoft Office 365 ProPlus Version 1708 (build 8431.2153)
    Posts
    62

    Re: Hide/Display radio buttons

    Hi Theo,

    It’s working beautifully! Thank you so much!

    Carlos

+ 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. Display/Hide radio buttons
    By no_Fate in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-01-2015, 04:38 PM
  2. Display/Hide radio buttons
    By no_Fate in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-17-2015, 05:11 AM
  3. [SOLVED] Using Radio Buttons to display Pictures
    By Chrizzo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-19-2013, 05:48 PM
  4. How do I setup radio buttons to display different worksheet data in graphs
    By Dan Murphy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-24-2010, 12:36 AM
  5. Using VBA to link Radio Buttons to Display an observation
    By isara912 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-16-2008, 09:55 AM

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