+ Reply to Thread
Results 1 to 7 of 7

Change Chart Axis Font Color with a Checkbox

  1. #1
    Registered User
    Join Date
    08-20-2014
    Location
    Kelowna, Canada
    MS-Off Ver
    2010
    Posts
    10

    Change Chart Axis Font Color with a Checkbox

    Hi all,

    Been searching the forums and the internet for a way to change the font color of a chart axis when a checkbox is set to true. I haven't been successful yet so that is why I am posting.

    let checkbox be checkbox5 and chart be chart5. What I would like to happen is that if checkbox5 is true then the font color of the horizontal axis changed to grey (RGB 166,166,166), if it is false then I would like the font color of the horizontal axis to be black (RGB 0,0,0). I also would like this macro to be run every time the checkbox changes, or the corresponding cell changes to TRUE or FALSE (it is in another sheet, say sheet2). I am not sure what I am missing but it might be something silly. This is the code I have so far but all it is doing is showing the chart as selected and not changing the font color. I would also like it to not physically select the chart, this is for a dashboard so the selecting of the chart throws off some of the visuals a bit, but not sure how to do change the chart values without selecting it.

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    01-03-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    163

    Re: Change Chart Axis Font Color with a Checkbox

    Try something like this:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-20-2014
    Location
    Kelowna, Canada
    MS-Off Ver
    2010
    Posts
    10

    Re: Change Chart Axis Font Color with a Checkbox

    Thanks for the reply.

    That code looks a lot cleaner than mine was, but doesn't seem to be doing the trick either. I have put the code in the sheet containing the checkbox and chart but clicking the checkbox on and off isn't having the desired result. If I select the first line of the macro and click run I get this error: Run-time error '438': Object doesn't support this property or method.

    Is there any way to double check the check box label? If I right click it on the worksheet it is labeled as "Check Box 5"..does that mean it is also CheckBox5?

  4. #4
    Forum Contributor
    Join Date
    01-03-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    163

    Re: Change Chart Axis Font Color with a Checkbox

    Hi Jason

    Sorry my bad, I didn't realize that you used a Form formant not Activex formant.

    So, now try this:

    Right click on your checkbox, choose "assign macro", then if you have something like Checkbox5_Click on the list select it, choose Edit and then paste this code:

    Please Login or Register  to view this content.

    Hope this help you.

  5. #5
    Registered User
    Join Date
    08-20-2014
    Location
    Kelowna, Canada
    MS-Off Ver
    2010
    Posts
    10

    Re: Change Chart Axis Font Color with a Checkbox

    Would it be more efficient to switch the check boxes to ActiveX?

  6. #6
    Forum Contributor
    Join Date
    01-03-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    163

    Re: Change Chart Axis Font Color with a Checkbox

    I'm sorry, but I'm not experienced enough in VBA to tell for 100% which one would be more efficient.
    But I think because of both codes are very simple, so difference in execution time and pc resources usage should be barely unnoticeable.
    As far as I know (and this comes from person very experienced in VBA) if you use controls for simple applications then use Form controls, otherwise use ActiveX.

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Change Chart Axis Font Color with a Checkbox

    for form checkbox

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  8. #8
    Registered User
    Join Date
    08-20-2014
    Location
    Kelowna, Canada
    MS-Off Ver
    2010
    Posts
    10

    Re: Change Chart Axis Font Color with a Checkbox

    Quote Originally Posted by Sbarro79 View Post
    Hi Jason

    Sorry my bad, I didn't realize that you used a Form formant not Activex formant.

    So, now try this:

    Right click on your checkbox, choose "assign macro", then if you have something like Checkbox5_Click on the list select it, choose Edit and then paste this code:

    Please Login or Register  to view this content.

    Hope this help you.
    Thanks, I got that to work but have now run into a new problem. I also have an "All" checkbox, that when clicked either makes all other checkboxes true or false. If I use that then the font color on the chart doesn't change. I could add a similar macro to that checkbox but then it is only changing the font color based on what it is and not on whether or not the checkbox beside it is true or false. I think I might try switching the checkboxes to ActiveX and trying your other suggested code and see if that solves it.


    EDIT: got the ActiveX checkboxes inserted but ran into a couple of aesthetics issues that I can't figure out. First one, if a checkbox does not have a caption it looks kind of blurred..can that be changed? Second, when there is a caption when the checkbox is clicked the caption looks like it is selected (dashed box goes around the caption), how do I make it so that does not happen?
    Last edited by JasonBoyd; 08-26-2014 at 12:14 PM.

+ 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] How to change axis font size for a bar chart
    By excelnoob61 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-07-2014, 03:15 PM
  2. [SOLVED] How to change the Font Properties of Chart Primary/Secondary X-Y Axis Title using VBA ?
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 05-09-2013, 09:49 AM
  3. Replies: 2
    Last Post: 02-04-2013, 02:00 PM
  4. Infuriating VB Excel chart issue - how to change y axis font color
    By Ace of Clubs in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 08-07-2009, 01:22 AM
  5. [SOLVED] change font color of first cell in data table attached to chart
    By momo in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 02-18-2005, 10:06 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