Hello))
I am trying to conditionally format my chart. I know that I can do it with "IF" statement (which I do successfully). But I want to format the fill color of my chart bars based on the cells' color (bars take the same color as cells). Something tells me that there should be an easy VBA code to do this. I am using the following code, but it does not work.
Sub ColorChartColumnsbyCellColor()
With Sheets("Data").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
[TABLE="width: 500"]
<tbody>[TR]
[TD]Country[/TD]
[TD]2015[/TD]
[/TR]
[TR]
[TD]Jamaica[/TD]
[TD]15[/TD]
[/TR]
[TR]
[TD]Mexico[/TD]
[TD]100[/TD]
[/TR]
[TR]
[TD]USA[/TD]
[TD]18[/TD]
[/TR]
[TR]
[TD]Canada[/TD]
[TD]250[/TD]
[/TR]
[TR]
[TD]Chile[/TD]
[TD]33[/TD]
[/TR]
</tbody>[/TABLE]
I am trying to conditionally format my chart. I know that I can do it with "IF" statement (which I do successfully). But I want to format the fill color of my chart bars based on the cells' color (bars take the same color as cells). Something tells me that there should be an easy VBA code to do this. I am using the following code, but it does not work.
Sub ColorChartColumnsbyCellColor()
With Sheets("Data").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
[TABLE="width: 500"]
<tbody>[TR]
[TD]Country[/TD]
[TD]2015[/TD]
[/TR]
[TR]
[TD]Jamaica[/TD]
[TD]15[/TD]
[/TR]
[TR]
[TD]Mexico[/TD]
[TD]100[/TD]
[/TR]
[TR]
[TD]USA[/TD]
[TD]18[/TD]
[/TR]
[TR]
[TD]Canada[/TD]
[TD]250[/TD]
[/TR]
[TR]
[TD]Chile[/TD]
[TD]33[/TD]
[/TR]
</tbody>[/TABLE]