Hello,
I have the following code, attempting to change the color of a data point based on a condition. If a certain value in a "named range" (used as source data for the chart) is 2 then the data point should look "green" on the graph.
Any and all the help will be much much appreciated.
I have the following code, attempting to change the color of a data point based on a condition. If a certain value in a "named range" (used as source data for the chart) is 2 then the data point should look "green" on the graph.
Code:
Sub Chrt()
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("Sheet1!tbl"), PlotBy:=xlRows
ActiveChart.SeriesCollection(1).XValues = "=Dyn.xls!quest"
ActiveChart.SeriesCollection(2).XValues = "=Dyn.xls!quest"
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet2"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = Sheets("sheet1").Cells(2, 7) '"dd"
.Axes(xlCategory).HasTitle = True
.Axes(xlCategory).AxisTitle.Characters.Text = "Keys"
.SeriesCollection(1).Points
'.Axes(xlSeries).HasTitle = False
'.Axes(xlValue).HasTitle = False
End With
Dim cell As Range
For Each cell In Range("tbl") '[I]the named range[/I]
If cell.Value = 1 Then '[I]the condition[/I]
ActiveChart.SeriesCollection(1).Point(14).Select ' getting an error here
With Selection
.Interior.ColorIndex = 43
End With
End If
Next cell
End Sub
Any and all the help will be much much appreciated.