VBA - Change bar chart color depending on name of data point (XValues)

  • Hi Everybody,



    I am currently working on model where I have a barchart as an output
    Basically what I'm trying to do is to change the colors of each data point in a bar chart depending on its name (XValues).


    I have in the input sheet the following columns:


    Name: Type:


    Volvo Car
    BMW Car
    Boening Airplane
    Zodiac Boat


    Type definition column:
    Car
    Boat
    Airplane


    I want the code to do the following (pseudo code):
    1) compare each data point in the bar chart with the name column
    2) if they are equal:
    3) compare the typ column with the typ_definition_column
    4) if they are equal
    5)set interior.color = RGB(x,y,z)


    I coded the following but can't get it to work (Nothing happens).
    Could somebody possibly point me out into the right direction?


    All help is appreciated!
    /Leo


  • Re: VBA - Change bar chart color depending on name of data point (XValues)


    Hi spokyboy,
    Nice to meet you.
    It's ideal to debug when macro isn't run as expected.
    Or press F8 key then variable's value is displayed in locale window on vbe window for each step.
    Regards, junho

  • Re: VBA - Change bar chart color depending on name of data point (XValues)


    Junho,


    Thanks a lot!
    I wasn't familiar with the f8 function. Very handy!


    It appears that charts apply an extra space after each "XValue"


    Once again thanks!

  • Re: VBA - Change bar chart color depending on name of data point (XValues)


    Hi,


    may be


    replace

    Code
    If vChrValues(iPoint) = vName(iName, 1) Then


    with


    Code
    If InStr(1,vChrValues(iPoint),vName(iName, 1),vbTextCompare) Then


    Edit: glad you got it working now.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!