+ Reply to Thread
Results 1 to 8 of 8

macros and excel, conditional color formatting

  1. #1
    Registered User
    Join Date
    04-02-2015
    Location
    florida, usa
    MS-Off Ver
    360
    Posts
    34

    macros and excel, conditional color formatting

    I recently posted... see link.... but I think it actually belongs in this forum

    http://www.excelforum.com/excel-charting-and-pivots/1076628-conditional-formatting-of-chart.html#post4040250

    I don't know anything about macros but as you can see in the link, I am trying to manipulate the colors of a chart.
    I found this link http://datapigtechnologies.com/blog/index.php/automatically-set-chart-series-colors-to-match-source-cell-colors/
    and was able to open the attached file. When I open it with mine, I am able to use the macro (from the last link) to run on my open workbook.

    How do I get this macro into my worksheet permanently.... again I know nothing about this sort of thing but I do have the developer toolbar

    And, the one I ran didn't work properly. The colors were supposed to match the table (C3:L3) but they are now white.

    capturer n.PNG
    Planning Tool 4-8-15.xlsx

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: macros and excel, conditional color formatting

    conditional format does not effect the cell format itself
    so if you run macro trying to collect the color of the cell it will be white because that is what the cell actually is

    now the code you pasted is for different colors in series not data points which you are looking for

    try this code to see if it does what you want

    Please Login or Register  to view this content.
    the color is fixed instead of 2-tone color scale you have in your CF....it will require different coding in order to do it like the CF
    Last edited by humdingaling; 04-08-2015 at 10:42 PM.
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Registered User
    Join Date
    04-02-2015
    Location
    florida, usa
    MS-Off Ver
    360
    Posts
    34

    Re: macros and excel, conditional color formatting

    erro.PNG

    I am having trouble with this.....

    The colors you posted make sense... I can just break it down further for ten separate colors...

    In the meantime I am getting an error when I use this macro. It says runtime error. What am I doing wrong?

  4. #4
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: macros and excel, conditional color formatting

    few things to check

    is your chart name different? if so
    >>Set cht = ActiveSheet.ChartObjects("Chart 2").Chart
    change Chart 2 to whatever your chart is called

    also the macro needs to be run on the sheet which has the chart

    also ten seperate colors is doable...so much coding to do though
    may want to investigate so logic to do it, let me research

  5. #5
    Registered User
    Join Date
    04-02-2015
    Location
    florida, usa
    MS-Off Ver
    360
    Posts
    34

    Re: macros and excel, conditional color formatting

    Planning Tool 4-8-15 v2.xlsm

    Thank you for looking at this!

    I've attached the workbook... the charts are on page "results by use" and they are still white.

    I am not sure what you mean by chart name.... at least I don't know where to look. The macro I referenced earlier worked on all tables at the same time (on this page at least.
    Last edited by PDAUGHE1; 04-09-2015 at 12:09 AM. Reason: forgot file

  6. #6
    Registered User
    Join Date
    04-02-2015
    Location
    florida, usa
    MS-Off Ver
    360
    Posts
    34

    Re: macros and excel, conditional color formatting

    The macro from the other page was as follows... but I like how yours can have different colors.



    Sub CellColorsToChart()
    Dim oChart As ChartObject
    Dim MySeries As Series
    Dim FormulaSplit As Variant
    Dim SourceRange As Range
    Dim SourceRangeColor As Long

    'Loop through all charts in the active sheet
    For Each oChart In ActiveSheet.ChartObjects

    'Loop through all series in the target chart
    For Each MySeries In oChart.Chart.SeriesCollection

    'Get Source Data Range for the target series
    FormulaSplit = Split(MySeries.Formula, ",")

    'Capture the first cell in the source range then trap the color
    Set SourceRange = Range(FormulaSplit(2)).Item(1)
    SourceRangeColor = SourceRange.Interior.Color

    On Error Resume Next
    'Coloring for Excel 2003
    MySeries.Interior.Color = SourceRangeColor
    MySeries.Border.Color = SourceRangeColor
    MySeries.MarkerBackgroundColorIndex = SourceRangeColor
    MySeries.MarkerForegroundColorIndex = SourceRangeColor

    'Coloring for Excel 2007 and 2010
    MySeries.MarkerBackgroundColor = SourceRangeColor
    MySeries.MarkerForegroundColor = SourceRangeColor
    MySeries.Format.Line.ForeColor.RGB = SourceRangeColor
    MySeries.Format.Line.BackColor.RGB = SourceRangeColor
    MySeries.Format.Fill.ForeColor.RGB = SourceRangeColor

    Next MySeries
    Next oChart

    End Sub

  7. #7
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: macros and excel, conditional color formatting

    oh there are multiple charts on the sheet

    try this code instead
    Please Login or Register  to view this content.
    if 0.1 or under white
    otherwise use the value % out of 255 to determine how much green to put into G section of RGB
    Attached Files Attached Files
    Last edited by humdingaling; 04-09-2015 at 12:44 AM. Reason: changed RGB comment

  8. #8
    Registered User
    Join Date
    04-02-2015
    Location
    florida, usa
    MS-Off Ver
    360
    Posts
    34

    Re: macros and excel, conditional color formatting

    Thank you! That is great!

+ 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. Extract cell value if it has conditional formatting color (Excel 2013)
    By Rickysnips in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-26-2014, 07:46 PM
  2. Copy Conditional Formatting Color Scales Excel 2007
    By catbert22 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-19-2014, 07:05 PM
  3. Replies: 6
    Last Post: 12-30-2013, 11:46 AM
  4. HELP! How to change color of text in excel using conditional formatting
    By ayupchap1 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-14-2013, 05:24 PM
  5. excel count cell with color conditional formatting
    By Marco in forum Excel General
    Replies: 6
    Last Post: 11-20-2005, 01:00 PM

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