Adding Scatter Chart Data Label If XValue > Value

364 views Asked by At

I have a scatter plot with 100+ series and I'd like to add some data labels to those series where the horizontal value is greater than the vertical value - i.e. where XValue>Value.

I use the following code to add data labels to all series:

Dim mySeries As Series
Dim seriesCol As SeriesCollection
Dim i As Integer

Set seriesCol = ActiveSheet.ChartObjects("Chart 1").Chart.SeriesCollection

For Each mySeries In seriesCol
    Set mySeries = ActiveSheet.ChartObjects("Chart 1").Chart.SeriesCollection(j)
    With mySeries
            .ApplyDataLabels
            .DataLabels.ShowSeriesName = True
            .DataLabels.ShowValue = False
            .DataLabels.Font.Size = 6
    End With
    j = j + 1
Next

I would assume I'd add an 'If' command prior to the 'With' command, along the following lines:

If ActiveSheet.ChartObjects("Chart 1").Chart.SeriesCollection(j).XValues > _
    ActiveSheet.ChartObjects("Chart 1").Chart.SeriesCollection(j).Values  Then

However this condition doesn't seem to work. I'd be grateful if you could point out where I've gone wrong...

Thanks!

0

There are 0 answers