My code is below and does not work very well or I don't know what I am doing.
I have a mid size table of about 200 rows delineated with start date-end date- service area.
Each service area is color coded , when the service area changes the color changes. I don't have any conditional formatting doing this I just picked a random fill color.
What this code does is pick the color of the 1st cell and applies it to every bar in my range I picked to create my bar chart so if the 1st cell is pink every bar in the chart is pink.
I need it to look at the cell range by color and name. It needs to pick color based on the value of the cell.
So if I picked 200 rows in the range it is all pink , the only way I work around this is I pick the ranges and create them individually by color it's the only way the chart displayed pink, blue yellow , green etc.
Does this makes any sense?
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
MySeries.Format.Line.ForeColor.RGB = SourceRangeColor
Next MySeries
Next oChart
End Sub
I have a mid size table of about 200 rows delineated with start date-end date- service area.
Each service area is color coded , when the service area changes the color changes. I don't have any conditional formatting doing this I just picked a random fill color.
What this code does is pick the color of the 1st cell and applies it to every bar in my range I picked to create my bar chart so if the 1st cell is pink every bar in the chart is pink.
I need it to look at the cell range by color and name. It needs to pick color based on the value of the cell.
So if I picked 200 rows in the range it is all pink , the only way I work around this is I pick the ranges and create them individually by color it's the only way the chart displayed pink, blue yellow , green etc.
Does this makes any sense?
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
MySeries.Format.Line.ForeColor.RGB = SourceRangeColor
Next MySeries
Next oChart
End Sub