PDA

View Full Version : Highlighting a specific marker in a line chart



kevvukeka
02-27-2015, 03:58 AM
Hi All,

I need some help with VBA.

In the attached file, I have a line chart and drop down list on top of it. The line chart contains labels from A to O. The drop down at the top contains the exact labels A to O.

When I select a particular label from the drop down I want the marker of that particular label(which is a circle here) in the chart to be highlighted in "Green" , the rest should be turned into some other color may be grey or any other color other than green.

Can someone help.

Thanks in advance.

p45cal
02-27-2015, 03:07 PM
in the sheet concerned's code module, try:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B2")) Is Nothing Then
With ActiveSheet.ChartObjects("Chart 1").Chart.SeriesCollection(1)
yy = .XValues
For i = 1 To UBound(yy)
If yy(i) = Range("B2").Value Then
mycolour = RGB(0, 176, 80)
Else
mycolour = RGB(200, 200, 200)
End If
.Points(i).Format.Fill.ForeColor.RGB = mycolour
Next i
End With
End If
End Sub

and a bit faster:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B2")) Is Nothing Then
With Me.ChartObjects("Chart 1").Chart.SeriesCollection(1)
.Format.Fill.ForeColor.RGB = RGB(200, 200, 200)
yy = .XValues
For i = 1 To UBound(yy)
If yy(i) = Range("B2").Value Then .Points(i).Format.Fill.ForeColor.RGB = RGB(0, 176, 80)
Next i
End With
End If
End Sub

kevvukeka
03-01-2015, 09:48 PM
Thanks a lot p45cal.. Problem solved.....:clap::thumb