none
method 'text' of object 'data label' failed RRS feed

  • Question

  • Hi,

    I am trying to plot a chart in the excel (2013 version) however I am getting an error like:

    Run-time error '-2147467259 (80004005)':
    Method 'Text' of object 'DataLabel' failed

    I am trying to accomplish to plot a timeline chart with the below code (exact error code line is highlighted):

    Sub AttachLabelsToActivities()
        Dim intCounter As Integer
        Dim xVals As String
        Dim intOffset As Integer
      
        'Select Activity Timeline chart
        ActiveSheet.ChartObjects("Chart 1").Activate
       
        ' Disable screen updating while the subroutine is run.
        Application.ScreenUpdating = False

        'Store the formula for the first series in "xVals".
        xVals = ActiveChart.SeriesCollection(1).Formula

        'Extract the range for the data from xVals.
        xVals = Mid(xVals, InStr(InStr(xVals, ","), xVals, _
              Mid(Left(xVals, InStr(xVals, "!") - 1), 9)))
        xVals = Left(xVals, InStr(InStr(xVals, "!"), xVals, ",") - 1)
        Do While Left(xVals, 1) = ","
            xVals = Mid(xVals, 2)
        Loop

        'intOffset is offset from start date column to the column from which label text is read.
        intOffset = ktplanActivityDescriptionCol - ktplanStartDateCol
        ' Attach a label to each data point in the chart.
        For intCounter = 1 To Range(xVals).Cells.Count
            ActiveChart.SeriesCollection(1).Points(intCounter).HasDataLabel = True
            ActiveChart.SeriesCollection(1).Points(intCounter).DataLabel.Text = Range(xVals).Cells(intCounter, 1).Offset(0, intOffset).Value 
        Next intCounter
    End Sub

    Thursday, January 21, 2016 12:49 PM

Answers

  • Run-time error '-2147467259 (80004005)':

    Method 'Text' of object 'DataLabel' failed


    That depends on your file, the cell contents and especially the other code, because ktplanActivityDescriptionCol and ktplanStartDateCol are not declared or written in your macro!

    I suggest to use this AddIn instead:
    http://www.appspro.com/Utilities/ChartLabeler.htm

    If you need further help please upload your file (maybe with anonymous data) on an online file hoster like www.dropbox.com and post the download link here.

    A macro to anonymize data in selected cells can be downloaded here:
    https://dl.dropboxusercontent.com/u/35239054/modAnonymize.bas

    Andreas.

    Thursday, January 21, 2016 3:01 PM
  • Hi RY89,

    I agree with Andreas, it would be helpful if you could share us a simple file to reproduce your issue.

    I made a test with DataLabel.Text, it worked correctly.

    Sub Op()
    For i = 1 To 11
    ActiveChart.SeriesCollection(1).Points(i).HasDataLabel = True
    ActiveChart.SeriesCollection(1).Points(i).DataLabel.Text = "ABC"
    Next i
    End Sub

    I suggest you try a constant value for DataLabel.Text to check whether it would work.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, January 22, 2016 6:41 AM

All replies

  • Run-time error '-2147467259 (80004005)':

    Method 'Text' of object 'DataLabel' failed


    That depends on your file, the cell contents and especially the other code, because ktplanActivityDescriptionCol and ktplanStartDateCol are not declared or written in your macro!

    I suggest to use this AddIn instead:
    http://www.appspro.com/Utilities/ChartLabeler.htm

    If you need further help please upload your file (maybe with anonymous data) on an online file hoster like www.dropbox.com and post the download link here.

    A macro to anonymize data in selected cells can be downloaded here:
    https://dl.dropboxusercontent.com/u/35239054/modAnonymize.bas

    Andreas.

    Thursday, January 21, 2016 3:01 PM
  • Hi RY89,

    I agree with Andreas, it would be helpful if you could share us a simple file to reproduce your issue.

    I made a test with DataLabel.Text, it worked correctly.

    Sub Op()
    For i = 1 To 11
    ActiveChart.SeriesCollection(1).Points(i).HasDataLabel = True
    ActiveChart.SeriesCollection(1).Points(i).DataLabel.Text = "ABC"
    Next i
    End Sub

    I suggest you try a constant value for DataLabel.Text to check whether it would work.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, January 22, 2016 6:41 AM