Hi I am trying to complete a task at work but unfortunately for me I know nothing about VBA/Macro coding. I found the code below online and it works great but not when I conditionally format the cells then excel reads a white background and my lines are white. I believe there could be a simple tweak using a previous forum I found here but I have no clue where to insert this tweak. Here is what I found:
"However , the following line in the code retrieves the color of the worksheet cell :
SourceRangeColor = SourceRange.Interior.Color
When a cell is conditionally formatted , the following statement can retrieve the color of the cell :
Activecell.FormatConditions(1).Interior.color
This assumes that the cell has only one CF formula.
If you can upload a complete workbook with the data and the chart , it will make everyone's job easier."
I need to use conditional formatting because on a weekly basis a brand may change from 2nd to 3rd and I need the color to go with it. here is the code that works FINE when I fill the cells. Can you help tweak it to work with a conditional format? Thank you all!!
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
"However , the following line in the code retrieves the color of the worksheet cell :
SourceRangeColor = SourceRange.Interior.Color
When a cell is conditionally formatted , the following statement can retrieve the color of the cell :
Activecell.FormatConditions(1).Interior.color
This assumes that the cell has only one CF formula.
If you can upload a complete workbook with the data and the chart , it will make everyone's job easier."
I need to use conditional formatting because on a weekly basis a brand may change from 2nd to 3rd and I need the color to go with it. here is the code that works FINE when I fill the cells. Can you help tweak it to work with a conditional format? Thank you all!!
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