+ Reply to Thread
Results 1 to 13 of 13

Changing checkbox background color - loop to check all tick boxes on sheet for status TRUE

  1. #1
    Registered User
    Join Date
    01-28-2016
    Location
    Western Austalia
    MS-Off Ver
    2010
    Posts
    36

    Changing checkbox background color - loop to check all tick boxes on sheet for status TRUE

    Hi there

    I need to change the background colour for checkboxes on my spreadsheet. I have managed to do this for a single checkbox as follows:

    Please Login or Register  to view this content.
    Now, I have well over 100 checkboxes on this sheet (eg sheet7) and was hoping not to have to copy this code that many times to cover all. Would appreciate some help with creating a loop to check for all tick boxes on the sheet and apply the colour change to the checkbox background when it comes across a box that is ticked.

    Many thanks in advance...

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,873

    Re: Changing checkbox background color - loop to check all tick boxes on sheet for status

    Here is some untested aircode you might want to try

    Please Login or Register  to view this content.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    01-28-2016
    Location
    Western Austalia
    MS-Off Ver
    2010
    Posts
    36

    Re: Changing checkbox background color - loop to check all tick boxes on sheet for status

    Sorry - didn't work - stays white whether ticked or not...

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,873

    Re: Changing checkbox background color - loop to check all tick boxes on sheet for status

    Post a sample workbook so that it can be tested and analyzed. As I indicated in my response, it was untested. I did not have your worksheet to evaluate.

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window (or use the paperclip icon).

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Changing checkbox background color - loop to check all tick boxes on sheet for status

    How were the checkboxes created, from the Forms or ActiveX toolbar?
    If posting code please use code tags, see here.

  6. #6
    Registered User
    Join Date
    01-28-2016
    Location
    Western Austalia
    MS-Off Ver
    2010
    Posts
    36

    Re: Changing checkbox background color - loop to check all tick boxes on sheet for status

    @ Norie - Active X . The code I posted worked for a single tick box, but would have to repeat it 100+ times for the other ones. Confidential document, so can't actually post the workbook as it also draws data from other spreadsheets.

    Tick boxes however are just true/false status and as I said - my code works, but need someway to loop through all checkboxes and apply the same. Unsure how though.. :-(

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Changing checkbox background color - loop to check all tick boxes on sheet for status

    Alan's code will work if you change "Checkbox" to "CheckBox".

    However it's not going to run when you click a checkbox unless you add something like this for each checkbox.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    01-28-2016
    Location
    Western Austalia
    MS-Off Ver
    2010
    Posts
    36

    Re: Changing checkbox background color - loop to check all tick boxes on sheet for status

    It will reduce code just slightly - still have to call it 100+ times in that case, which I am trying to avoid in case the color needs to be changed in future. Hoping to only have to do this in one spot. Not that familiar with VBA, so am not sure how to call objects and use their attributes.

    The error with Alan's code that comes up is RUn-time error '438': object doesn't support this property or method. at If objx.Value = True then objX.Backcolor = RGB(255,0,0)

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Changing checkbox background color - loop to check all tick boxes on sheet for status

    Oops, I forgot about the other change(s) I made to get the code to work and they are kind of important.
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    01-28-2016
    Location
    Western Austalia
    MS-Off Ver
    2010
    Posts
    36

    Re: Changing checkbox background color - loop to check all tick boxes on sheet for status

    @ Norrie

    Pretty close to what I got to work in the end - slightly different, but still works.

    Code as follows

    Please Login or Register  to view this content.
    Had to put the ElseIf in as otherwise my buttons were also changed to white background!

    At the moment, I am calling this sub as part of a button press, so colour doesn't take effect until the button is pressed.
    But wondering if there is any way to have the colour change as soon as the box is ticked / unticked (like a click event, but one which doesn't require all tick boxes to have this click event sub - one that covers all tick boxes if and when they are clicked).

    Not sure if this can be done, but just putting it out there!

    Thanks for the suggestions so far!

  11. #11
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,873

    Re: Changing checkbox background color - loop to check all tick boxes on sheet for status

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  12. #12
    Registered User
    Join Date
    01-28-2016
    Location
    Western Austalia
    MS-Off Ver
    2010
    Posts
    36

    Re: Changing checkbox background color - loop to check all tick boxes on sheet for status

    It hasn't entirely resolved my query yet. The original code I posted was a click event, which changed the colour immediately when the box was ticked.
    The code I ended up with does loop through all the tick boxes, but will only apply the colouring AFTER a button is pressed to check all the tick boxes.

    Was hoping to be able to modify this code further so that it takes effect the minute each tick box is selected, without relying on a button press after the whole survey has been completed.

    Thank you...

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Changing checkbox background color - loop to check all tick boxes on sheet for status

    You could set up a class to handle the Click event of the checkboxes.

    I think I've got some code for that somewhere and I'll post it later, if I can locate it.

+ 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. Changing Background Color for Active Cells, then back to Previous Color...
    By TMCinDC in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-13-2016, 11:35 AM
  2. Replies: 1
    Last Post: 09-24-2015, 11:50 AM
  3. Check boxes that delete other check boxes and change the color of another cell.
    By nhamhamilton in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-29-2014, 02:40 PM
  4. [SOLVED] Increment through Checkbox's to check status and change a value
    By vamosj in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-03-2014, 04:07 PM
  5. Excel VBA to generate check boxes and restrict user to tick on the 3 boxes in a row
    By rhodalynn.rona in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-06-2012, 05:55 AM
  6. How to add to macro & have checkbox match background color?
    By jgomez in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-16-2012, 11:26 AM
  7. [SOLVED] Check / Tick Boxes
    By tinahumphries in forum Excel General
    Replies: 1
    Last Post: 09-02-2005, 10: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