Runtime error 5, Chart Labels
===

After running a meta-analysis, I am trying to add labels to the chart using the macro below in (VBA) Excel 2007 but I keep getting Runtime Error 5 : Invalid procedure call or argument. Any thoughts? The error line is marked with **

    'create scatterplot on sheet k
    Private Sub graphcustom(ByVal k As Integer, ByVal ptype As Boolean)
    Dim rowcnt, textsize, cntr, labeltop As Integer
    Dim minchar As Double
    Dim maxchar As Double
    Dim midchar As Double
    Dim tboxend As Double
    Dim tboxstep As Double
    Dim tboxpos As Double
    Dim xvdata As Range
    Dim vdata As Range
    Dim edata As Range
    Dim rngtemp As Range
    Dim sheetname As String
    Dim WS As Worksheet
    Dim int1, int2, int3, chartleftpos, labelcol, labelsize, chartmultipl As Integer
    Dim minscale As Integer
    Dim i, j As Integer
    Dim mu(1 To 5), mvar(1 To 5), tmargin(1 To 5) As Double
    Dim Sh As Shape
    Dim minsc, maxsc As Double
    Dim tlabel(1 To 5) As String
    Dim sharray() As Variant
    Dim wsum, tweight As Double
    Dim sqsize() As Double
    Dim minsq, multipl, maxsq As Double
    'edit according to type of scatterpolt. True = summary scatter, False = methods scatter
    If ptype Then
        int1 = 4
        int2 = 9
        int3 = 7
        chartmultipl = 10
        chartleftpos = 500
        minscale = 0
        labelcol = 3
        labelsize = 7
    Else
        int1 = 2
        int2 = 6
        int3 = 5
        chartmultipl = 40
        chartleftpos = 350
        minscale = -5
        labelcol = 1
        labelsize = 10
    End If
    Application.ScreenUpdating = False
    'activate sheet and set it for easier reference
    Worksheets(k).Activate
    Set WS = Worksheets(k)
    'get the last row of data
    rowcnt = LASTINCOLUMN2(6, k)
    'get the data ranges for XValues
    Set xvdata = WS.Range(WS.Cells(2, int1), WS.Cells(rowcnt, int1))
    Set vdata = WS.Range(WS.Cells(2, int2), WS.Cells(rowcnt, int2))
    Set edata = WS.Range(WS.Cells(2, int3), WS.Cells(rowcnt, int3))
    'if it is a final chart calculate the weights of the graph points
    If Not ptype Then
        'denominator
        wsum = 0
        For i = 1 To resultcount
            wsum = wsum + 1 / vareffects(i)
        Next i
        'resize size of array
        ReDim sqsize(1 To resultcount) As Double
        'numerator
        For i = 1 To resultcount
            tweight = (1 / vareffects(i)) / wsum
            'from temp weight go to the square size
            sqsize(i) = Sqr(tweight)
        Next i
        'resize squares to a normal range (to the allowed 2-72 range)
        minsq = sqsize(1)
        For i = 2 To resultcount
            If sqsize(i) < minsq Then minsq = sqsize(i)
        Next i
        'first try to resize based on the smaller one
        multipl = 5 / minsq
        For i = 1 To resultcount
            sqsize(i) = sqsize(i) * multipl
        Next i
        'if the larger one is above 40 then we resize down to 40
        maxsq = sqsize(1)
        For i = 2 To resultcount
            If sqsize(i) > maxsq Then maxsq = sqsize(i)
        Next i
        If maxsq > 40 Then
            multipl = 40 / maxsq
            For i = 1 To resultcount
                sqsize(i) = sqsize(i) * multipl
                If sqsize(i) < 2 Then sqsize(i) = 2
            Next i
        End If
    End If
    'add and edit the chart
    Charts.Add
    With ActiveChart
        .ChartType = xlXYScatter
        .SetSourceData Source:=xvdata, PlotBy:=xlColumns
        .Location Where:=xlLocationAsObject, Name:=WS.Name
    End With
    With ActiveChart
        With .SeriesCollection(1)
            .XValues = xvdata
            .Values = vdata
            .ErrorBar Direction:=xlX, Include:=xlBoth, Type:=xlCustom, Amount:=edata,  MinusValues:=edata
            .MarkerBackgroundColorIndex = 1
            .MarkerForegroundColorIndex = 1
            .MarkerStyle = xlSquare
            .MarkerSize = 5
        End With
        .Axes(xlCategory, xlPrimary).HasTitle = False
        .Axes(xlValue, xlPrimary).HasTitle = False
        .HasLegend = False
        .HasTitle = False
        .Axes(xlCategory).HasMajorGridlines = False
        .Axes(xlCategory).HasMinorGridlines = False
        .Axes(xlValue).HasMajorGridlines = False
        .Axes(xlValue).HasMinorGridlines = False
        .PlotArea.Interior.ColorIndex = xlNone
    End With
    With ActiveChart.Axes(xlValue)
        .MinimumScale = minscale
        .MaximumScale = rowcnt
        .MinorUnit = rowcnt
        .MajorUnit = rowcnt
        .Crosses = xlCustom
        .CrossesAt = minscale
        .ReversePlotOrder = False
        .ScaleType = xlLinear
        .DisplayUnit = xlNone
        .MajorTickMark = xlNone
        .MinorTickMark = xlNone
        .TickLabelPosition = xlNone
    End With
    With ActiveChart.Axes(xlCategory)
        .TickLabels.NumberFormat = "0.0"
        .MinorUnit = 0.1
        .MajorUnit = 0.5
        'don't allow a minimum or maximum scale of 0
        If .MinimumScale = 0 Then
            .MinimumScale = -.MaximumScale
        End If
        If .MaximumScale = 0 Then
            .MaximumScale = -.MinimumScale
        End If
    End With
    'resize chart
    WS.ChartObjects(1).Width = 500
    WS.ChartObjects(1).Height = chartmultipl * (rowcnt - 1 - minscale)
    WS.ChartObjects(1).Left = chartleftpos
    WS.ChartObjects(1).Top = 70
    'Rescale values to positions in chart so that labels can be succesfully moved
    minchar = ActiveChart.Axes(xlCategory).MinimumScale
    maxchar = ActiveChart.Axes(xlCategory).MaximumScale
    midchar = (maxchar + minchar) / 2
    'datalabels
    **ActiveChart.SeriesCollection(1).ApplyDataLabels AutoText:=False, LegendKey:= _
        False, ShowSeriesName:=False, ShowCategoryName:=False, ShowValue:=True, _
        ShowPercentage:=False, ShowBubbleSize:=False**
    