I am trying create a chart using cell colors from the active cells on a specific worksheet. When using the macro provided below I find that only some of the assigned cell RGB color codes match to the chart. I am not sure why some colors would match and some would not. The correct colors display in the chart when I manually enter the color codes. Is there something I am leaving out of this macro or an extra step I need to take?
I am using Excel 2016 for this project.
Sub ColorChartColumnsbyCellColor()
With Sheets("Sheet1").ChartObjects(1).Chart.SeriesCollection(1)
Set vAddress = ActiveSheet.Range(Split(Split(.Formula, ",")(1), "!")(1))
For i = 1 To vAddress.Cells.Count
.Points(i).Format.Fill.ForeColor.RGB =
ThisWorkbook.Colors(vAddress.Cells(i).Interior.ColorIndex)
Next i
End With
End Sub
Set vAddress = ActiveSheet.Range(Split(Split(.Formula, ",")(1), "!")(1))
. Unfortunately, I don't know what you're trying to do with that nested split so I don't know how to help you. Try toAssert
that line to see if you're getting the expected result. – Fernando J. RiveraDisplayFormat.Interior.Color
Those colors will not be reflected inCells(i).Interior.ColorIndex
- that will return the "base/resting" color of the cell without any CF changes applied – Tim Williams