+ Reply to Thread
Results 1 to 4 of 4

Defining chart colours by cell entries

Hybrid View

banana-pumpkin Defining chart colours by... 08-25-2010, 05:51 AM
Andy Pope Re: Defining chart colours by... 08-25-2010, 08:08 AM
banana-pumpkin Re: Defining chart colours by... 08-25-2010, 08:24 AM
Andy Pope Re: Defining chart colours by... 08-25-2010, 08:57 AM
  1. #1
    Registered User
    Join Date
    08-13-2010
    Location
    Slough, UK
    MS-Off Ver
    Excel 2010
    Posts
    18

    Defining chart colours by cell entries

    I have some VBA code that I am using to change the background colour of cells in my column A using values in columns B,C,D to define the RGB components of the colour.
    e.g. Red | 255 | 0 | 0 turns the first cell's background to red.

    I've created a column chart using the column A values as x-values and some other data in column E as y-values. What I want is to make the fill colour of the columns in the chart the same as the background colour of the cells in the worksheet.

    Please see attached file - thanks in advance for your help
    Attached Files Attached Files

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

    Re: Defining chart colours by cell entries

    It could be that using dummy series and formula is a better approach. Hard to tell with such a contrived example and no explanation of actual usage.

    Anyway here is some code.

    Sub ColourChart()
    
        Dim chtTemp As Chart
        Dim objSeries As Series
        Dim rngAxisLabels As Range
        Dim lngIndex As Long
        
        Set chtTemp = ActiveSheet.ChartObjects(1).Chart
        Set rngAxisLabels = Range(Split(chtTemp.SeriesCollection(1).Formula, ",")(1))
        
        Set objSeries = chtTemp.SeriesCollection(1)
        lngIndex = 0
        For Each rngcell In rngAxisLabels
            lngIndex = lngIndex + 1
            objSeries.Points(lngIndex).Format.Fill.ForeColor.RGB = rngcell.Interior.Color
        Next
        
    End Sub
    I have used a very quick and dirty method of getting the range used for axis labels. In real-world usage you may need something more robust to extract the parameter.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    08-13-2010
    Location
    Slough, UK
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Defining chart colours by cell entries

    Thanks, Andy - I'll have a play with that and see if I can get it to work.

    It's not actually a contrived example; I work for a paint company so the real usage is exactly the same, just with more colours and "Chart Value" replaced with our profit figures.

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

    Re: Defining chart colours by cell entries

    Ah, okay. I though you might be going for some sort of RAG chart.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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