Close

Results 1 to 11 of 11

Thread: Excel question

  1. #1
    DF VIP Member Karoline's Avatar
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,551
    Thanks
    106
    Thanked:        59
    Karma Level
    467

    Default Excel question

    Is there a way to do the following thing in excel. Say I have some data in the spreadsheet. Eg numbers . Some of them are highlighted due to certain reasons and such. These are put into a graph. Is there a way so that the graph has the same coloured bars than the highlighted cells?
    So in other words the graph bars will be at least 2 different colours depending on if the data is highlighted or not?

  2. #2
    DF VIP Member cassy34's Avatar
    Join Date
    Nov 2004
    Location
    Lytham
    Posts
    1,453
    Thanks
    246
    Thanked:        181
    Karma Level
    359

    Default Re: Excel question

    Hi Karoline, what version of Excel are you using?

    Also, will the cells be coloured differently using conditional formatting or just changing the background of each cell as those 2 methods are accessed differently in VBA and if it's conditional formatting, it's a bastard to evaluate.

    Oh, this will have to be done via a macro BTW.
    Last edited by cassy34; 15th October 2010 at 03:42 PM.

  3. #3
    DF VIP Member Karoline's Avatar
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,551
    Thanks
    106
    Thanked:        59
    Karma Level
    467

    Default

    Hi, I think it is 2000 version. The cells are just highlighted, we don't use conditional formatting for it, we just change the background colour really.

  4. #4
    DF VIP Member RUDE BOI's Avatar
    Join Date
    Apr 2002
    Location
    E55EX BOY
    Posts
    264
    Thanks
    54
    Thanked:        16
    Karma Level
    287

    Default Re: Excel question

    I believe excel can only tell the colour of a cell, if it is excel 2007+.
    So in your situation sadly I don't think it can be done.

    You can have a drop down box next to each cell stating the colour, and the cell would change automatically (using conditioning formatting). Then this can be picked up by the graph (macro needed).

    Edit: Having a quick google i realise it is possible, I must have been thinking about that fact your cant autofilter based on colour pre2007
    Last edited by RUDE BOI; 16th October 2010 at 06:01 PM.
    [DF] RUDE BOI BEN C

  5. #5
    DF VIP Member cassy34's Avatar
    Join Date
    Nov 2004
    Location
    Lytham
    Posts
    1,453
    Thanks
    246
    Thanked:        181
    Karma Level
    359

    Default Re: Excel question

    Have a go with the following code. Alternatively, if you post the spreadsheet I should be able to get it working. To get this working, press ALT+F11 to open a code window. Insert a new module (Insert > Module) from the top menu. The copy the following code in. To get it to run either press F5 or F8 to step through a line at a time.

    Public Sub ColourGraph()

    Dim c As Range
    Dim x As Integer
    x = 0
    Worksheets("Sheet1").ChartObjects(1).Activate
    ActiveChart.ChartArea.Select

    ' Change the range for the one you're working with.
    ' This will change the colour of each bar to the background colour of the corresponding cell. You can play around with this by using an IF statement
    For Each c In Worksheets("Sheet1").Range("B4:B17").Cells

    x = x + 1
    Worksheets("Sheet1").ChartObjects(1).Chart.SeriesCollection(1).Points(x).Select
    With Selection.Interior
    .ColorIndex = c.FormatConditions(1).Interior.ColorIndex
    .Pattern = xlSolid
    End With
    Next


    End Sub

  6. #6
    DF VIP Member Karoline's Avatar
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,551
    Thanks
    106
    Thanked:        59
    Karma Level
    467

    Default Re: Excel question

    Thanks, i will try this, and let you know how i get on, thanks very much

  7. #7
    DF VIP Member Karoline's Avatar
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,551
    Thanks
    106
    Thanked:        59
    Karma Level
    467

    Default Re: Excel question

    Hi, i tried this, but i am not sure if i am doing it correctly.
    When i run it, the following error comes up ..

    Run time error 1004 - Unable to get the ColorIndex property of the interior class...

  8. #8
    DF VIP Member cassy34's Avatar
    Join Date
    Nov 2004
    Location
    Lytham
    Posts
    1,453
    Thanks
    246
    Thanked:        181
    Karma Level
    359

    Default Re: Excel question

    This may be a limitation of Excell 2000. I'll try and get hold of a copy and see if anything can be done.

  9. #9
    DF VIP Member cassy34's Avatar
    Join Date
    Nov 2004
    Location
    Lytham
    Posts
    1,453
    Thanks
    246
    Thanked:        181
    Karma Level
    359

    Default Re: Excel question

    Hi Karoline.

    I've installed Excel 2000 and tweaked the code a bit so hopefully this will do the trick. I'm assuming that this is a simple bar graph with only 1 range (series) defined. If not, i'll probably need to have a look at it to get a solution.

    Public Sub ColourGraph()

    Dim c As Range
    Dim x As Integer
    x = 0
    Worksheets("Sheet1").ChartObjects(1).Activate
    ActiveChart.ChartArea.Select

    ' Change the range for the one you're working with.
    ' This will change the colour of each bar to the background colour of the corresponding cell. You can play around with this by using an IF statement

    For Each c In Worksheets("Sheet1").Range("B4:B17").Cells

    x = x + 1
    ActiveChart.SeriesCollection(1).Points(x).Select
    With Selection.Interior
    .ColorIndex = c.Interior.ColorIndex
    .Pattern = xlSolid
    End With
    Next


    End Sub

  10. #10
    DF VIP Member Karoline's Avatar
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,551
    Thanks
    106
    Thanked:        59
    Karma Level
    467

    Default

    thanks very much again, will try this out tomorrow

  11. #11
    DF VIP Member Karoline's Avatar
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,551
    Thanks
    106
    Thanked:        59
    Karma Level
    467

    Default Re: Excel question

    Wow, thanks very much. This worked great on 2000 Tested on 2003 also and i got it working, thanks very much.

Similar Threads

  1. redirect question
    By Psychoschiz in forum Web Hosting & Domain Names
    Replies: 2
    Last Post: 26th September 2002, 04:09 PM
  2. Quick Saturn question
    By doughboy in forum Old Skool Gaming & Retro
    Replies: 1
    Last Post: 16th September 2002, 02:19 AM
  3. Xbox DVD Rom question
    By nims076 in forum Microsoft Consoles
    Replies: 12
    Last Post: 1st September 2002, 04:21 PM
  4. 5210 question
    By miniboot in forum Unlocking Questions & Solutions
    Replies: 1
    Last Post: 29th August 2002, 12:36 PM
  5. Decorating Question
    By Roty in forum The Dog and Duck
    Replies: 6
    Last Post: 28th August 2002, 11:36 AM

Social Networking 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
  •