Question : EXCEL: Putting data labels automatically on a scatter graph.

I have a scatter graph made up from 2 columns. The 3rd column has the datalabels that I want to put next to each point on the graph. With only a few points, I've been able to manually enter these labels. However, now I have too many points and I would like to find an automated way of doing this. Everytime I try and link up the 1st column which contains the datalabels, it messes up the graph. I've tried making an array but have not been able to link up the individual array segments with the different segments of the seriescollection which make up the points' position. The code is below:

Sub OldQ2_Chart()


    Dim xRng As Object
    Dim Old_Q2Chart As Chart
   
    ActiveSheet.ChartObjects.Delete
   
   'Create a new chart.
    Set Old_Q2Chart = Charts.Add
    'Set Old_Q2Chart = Old_Q2Chart.Location(Where:=xlLocationAsObject, Name:="10Yr_LowWACC_Charts")
    'Create a new Chart area
    Dim Old_Q2ChartArea As ChartArea
    Set Old_Q2ChartArea = Old_Q2Chart.ChartArea
    'create a new plot area
    Dim PltArea As PlotArea
    Set PltArea = Old_Q2Chart.PlotArea
    Dim nPts As Long


    'fill in the chart area
    With Old_Q2Chart
        .ChartType = xlXYScatter
 
       
        .SetSourceData Worksheets("Old_Q2").Range("e1:f15")
        .PlotBy = xlColumns
       
        .SeriesCollection(1).XValues = "=(Old_Q2!R2C5:R15C5)"
       
        .SeriesCollection(1).Values = "=(Old_Q2!R2C6:R15C6)"
  '      Range("=(Old_Q2!R2C4:R15C4)").Select

        'Range("D2:D15").Select
       
        With .SeriesCollection(1)
        .HasDataLabels = True
            With .DataLabels
                '.DataLabel.Text = "=Old_Q2!R2C4:R15C4"
            End With
        End With

       
        With .Axes(xlValue)
            '.DisplayUnit = xlCustom
            '.DisplayUnitCustom = 1000
            .HasTitle = True
            .AxisTitle.Caption = "Time of Impact (Years)"
        End With
        .HasTitle = False
        .HasLegend = True
        With .Axes(xlCategory)
            '.CategoryLabels = True
            .HasTitle = True
            .AxisTitle.Caption = "Old Quarter 2"
        End With
       
        .Name = "Old_Q2 Chart"
      End With
         
End Sub

The data is:
.Net2      -2      14
3DP      -5      1
AIR      -8      6
L5R      -1      14
APS      -1      15.25
ASP.Net2      -2      14
Areal      -6      6
Biom      -3      15
BlueT      -1      8
BOPL      -5      8
BAM      -2      11
BPEL      -3      7
BPM      -1      17
BRE      -1.5      15.25

Hope someone can work it out.

Henry

Answer : EXCEL: Putting data labels automatically on a scatter graph.

you also might take a look at:
http://www.microsoft.com/europe/vba/resources/downloads/128.htm

or:
http://www.appspro.com/Utilities/ChartLabeler.htm

regards,
Jeroen
Random Solutions  
 
programming4us programming4us