+ Reply to Thread
Results 1 to 12 of 12

VBA to Enable Form Control Check Boxes Based on Value of Another Cell

  1. #1
    Registered User
    Join Date
    05-22-2021
    Location
    US
    MS-Off Ver
    Excel 365
    Posts
    58

    VBA to Enable Form Control Check Boxes Based on Value of Another Cell

    I have some check boxes in which depending on the value on of cell H264 the check boxes will appear with some being enabled for use. Enabling some of the check boxes is where I had problems. Below are the options I came up with - with my preferences in order. But I open to suggestions if anyone has anything better or easier.

    My 1st option was to disable/lock (or prevent the user from being able to click on the check box) certain check boxes if H264 =1 but I could not figure out the VBA code. So option 2 was to perhaps determine a way to change the color of the actual check-mark to white when H264 =1 to give the effect that the check boxes are disabled even if the user clicked the check box. But I could not determine how to do that either.

    So I went to option 3 (my least favorite option), which would be to fill the interior color of the check box to black so if the user clicks the check box, you cannot tell it has been checked because the check-mark is black and the check box is filled black - so it essentially has the effect of being disabled.

    My VBA knowledge is limited. Below is what I have but this doesn't fill the interior of the check box. It instead fills the outer edge of the check box.

    Please Login or Register  to view this content.

    I appreciate any help offered.

  2. #2
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    365 32bit Win
    Posts
    1,935

    Re: VBA to Enable Form Control Check Boxes Based on Value of Another Cell

    It looks like the checkboxes are always visible, so you could do something like this to change the enabled status of the 4 and also grey the check out using the mixed status.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-22-2021
    Location
    US
    MS-Off Ver
    Excel 365
    Posts
    58

    Re: VBA to Enable Form Control Check Boxes Based on Value of Another Cell

    Sorry, it was last when I posted last night and I was trying to get one part to work. When that failed, I didn't give complete scenario. The checkboxes must show but the user should not be allowed to click the disabled checkboxes or if they can, then the check-mark (if they click it) must not be visible so that it looks like the checkboxes are disabled.

    Here is complete scenario.
    If H264=0 then enable all checkboxes

    If H264=1 then enable check boxes 144 and 145
    and disable check boxes 104, 105, 106 and 216

    If H264=2 then disable all checkboxes
    Last edited by ellenlewis; 06-15-2021 at 10:00 AM.

  4. #4
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    365 32bit Win
    Posts
    1,935

    Re: VBA to Enable Form Control Check Boxes Based on Value of Another Cell

    Maybe this?

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-22-2021
    Location
    US
    MS-Off Ver
    Excel 365
    Posts
    58

    Re: VBA to Enable Form Control Check Boxes Based on Value of Another Cell

    I appreciate your response. This isn't quite working for me. When H264 is 1 or 2, the checkboxes are the same. They are all supposed to be disabled when H264 is 2. Also, the mixed (or greyed) doesn't really disable the checkbox. The user can still click the checkbox and make a check-mark appear. Was hoping for a way to dis-allow the user from being able click the box or being able to see the check-mark.

  6. #6
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    365 32bit Win
    Posts
    1,935

    Re: VBA to Enable Form Control Check Boxes Based on Value of Another Cell

    It works for me. Maybe post your workbook?

  7. #7
    Registered User
    Join Date
    05-22-2021
    Location
    US
    MS-Off Ver
    Excel 365
    Posts
    58

    Red face Re: VBA to Enable Form Control Check Boxes Based on Value of Another Cell

    ByteMarks -
    Apologies for delay. I have attached the workbook as suggested. I tried re-writing the code (somewhat started over) with partial luck. Your code with the checkboxes are a perfect solution if I can understand the code and get them working completely. Thanks so much for the suggestion!! The checkboxes do somewhat work now but I am still doing something wrong. I'm not sure I understand the code.

    There are 3 sections I need the checkboxes to enable and disable checkboxes (Gender, Ethnicity, and Race). I figure if I can get the Ethnicity working, I hoping I can figure out the other 2 sections. So in testing myself to see if I understand the code, I tried writing it out differently for the Gender section but it didn't work, so I don't think I understand some of the lines but I'm not giving up.

    Perhaps I'm missing it in the coding but I'm looking for where it enables some checkboxes while disabling the others (looks like now either all are enabled
    or disabled). I've included notes below as well as in macro.

    When H264=0 All checkboxes are unlocked
    When H264=1 2 checkboxes are unlocked and others are locked
    When H264=2 All checkboxes are locked

    Thanks!
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    365 32bit Win
    Posts
    1,935

    Re: VBA to Enable Form Control Check Boxes Based on Value of Another Cell

    To try and explain the code, going back to the original example:

    H264 = 0: all boxes enabled
    H264 =1: 144 and 145 enabled: 104, 105, 106, 216 disabled
    H264 =2: all boxes disabled

    It might help to rename the checkboxes to something more meaningful.

    I've added some comments to the code which I hope will explain how this works.
    Basically, H264 =1 was the only setting where there was a mix of enabled/disabled, so the code is split between whether H264 is 1 or not.


    Please Login or Register  to view this content.
    Last edited by ByteMarks; 07-08-2021 at 10:55 AM.

  9. #9
    Registered User
    Join Date
    05-22-2021
    Location
    US
    MS-Off Ver
    Excel 365
    Posts
    58

    Re: VBA to Enable Form Control Check Boxes Based on Value of Another Cell

    This explanation was REALLY helpful. Thanks so much. But how to do I apply that for each section? I write this code for each section. Is that how I should have done it? Works perfect for Race, but it enables and disables the checkboxes in the Gender section as well as the Ethnicity section. If the data is collected in person, the patient may not be willing to provide Ethnicity so only the bold items Not Hispanic and Hispanic checkboxes would be enabled in that section but the patient may not willing to provide Race so all of the checkboxes in the race section would be enabled. Each section has its' own indicator so I wrote the code for each section but didn't end with quite the right results.

  10. #10
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    365 32bit Win
    Posts
    1,935

    Re: VBA to Enable Form Control Check Boxes Based on Value of Another Cell

    I would have a separate Sub for each section which will make testing and working out the enabled states easier.
    I'd also give the checkboxes a section-specific name e.g. Gender1, Gender2 etc.
    Then you can you can work out the enabled states and triggers for each section and test it.

    If each section's boxes will operate independently of other sections then you could group them and then loop through the group rather than every box on the worksheet.
    So, if you grouped Gender1 and Gender2 in a group called GroupGender

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    05-22-2021
    Location
    US
    MS-Off Ver
    Excel 365
    Posts
    58

    Re: VBA to Enable Form Control Check Boxes Based on Value of Another Cell

    It took several tries, but I got it! ByteMarks - I really appreciate your help and the explanation to the code. It was a BIG help for a newbie like myself!! Thanks again and have a great week!

  12. #12
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    365 32bit Win
    Posts
    1,935

    Re: VBA to Enable Form Control Check Boxes Based on Value of Another Cell

    Well done, that's great. I'm pleased I was able to help.

+ 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] Hiding form control check boxes
    By Gti182 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-03-2016, 07:14 AM
  2. [SOLVED] Working with Check Boxes (Form Control)
    By Utzja1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-02-2015, 09:40 AM
  3. Changing box and font size in form control check boxes?
    By Hambone70 in forum Excel General
    Replies: 3
    Last Post: 08-13-2014, 10:16 AM
  4. Replies: 2
    Last Post: 04-29-2013, 07:25 PM
  5. [SOLVED] Control numerical index based on check boxes
    By Excel white-belt in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-18-2012, 11:04 AM
  6. [SOLVED] Need help with Form Control Check Boxes Please
    By colescharton in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-06-2012, 01:03 PM
  7. Enable check box in protected sheet + group check boxes
    By Dexxterr in forum Excel General
    Replies: 4
    Last Post: 08-02-2006, 07:05 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