Excel VBA - Add Data Labels from Table body range











up vote
0
down vote

favorite












I have an Excel worksheet with a table that contains columns for project name, x, y, size in order to create a bubble graph.



I would like it to change the Data labels to be equal to the respective project name but how do I do that? I've searched on the web for solutions but neither of them with succes.



Here's my data:




  • Chart name: Chart 1

  • Table name: Table (This one have headers and I'm
    only searching for the range within the table (data body range).


Here's my code which gives me the error 91:



Sub InsertLabelnameBubble()
ActiveChart.FullSeriesCollection(1).DataLabels.Select

For i = 1 To Range("Table").Rows.Count
ActiveChart.FullSeriesCollection(1).Points(i).DataLabel.Select
Selection.Formula = Range("Table").Cells(i, 1)
Next i
End Sub


Here's a screenshot of my project.



Screenshot 1



Where you can see that it uses the Y column (Expected project potential) as the data label text. What I would like it to do is that it should take it from the first column in my table (Project #).










share|improve this question




















  • 3




    Maybe include some screen shots. Doesn't seem clear what you're asking for.
    – PGCodeRider
    Oct 31 at 14:28






  • 1




    Also, which line are you receiving the error? Error 91 means you are trying to use an object set to Nothing
    – Kubie
    Oct 31 at 14:33






  • 2




    See The VBA Guide To ListObject Excel Tables for how to properly access a table in Excel VBA. You must probably use something like ActiveSheet.ListObjects("Table").DataBodyRange(i, 1)
    – Pᴇʜ
    Oct 31 at 14:41












  • Am I allowed to upload my project file somewhere and post the link here? I'm not sure a screenshot is enough, and I'm really searching for a solution, which should be included in my Master's thesis.
    – Rasmus Holt Hansen
    Nov 1 at 11:19










  • You could manually link your labels to cells. Use a formula to pull the correct project name into a specific cell and then click your label twice before selecting the formula bar and then your cell. John Peltier explains it on his site - third heading.
    – Darren Bartrup-Cook
    Nov 5 at 14:17















up vote
0
down vote

favorite












I have an Excel worksheet with a table that contains columns for project name, x, y, size in order to create a bubble graph.



I would like it to change the Data labels to be equal to the respective project name but how do I do that? I've searched on the web for solutions but neither of them with succes.



Here's my data:




  • Chart name: Chart 1

  • Table name: Table (This one have headers and I'm
    only searching for the range within the table (data body range).


Here's my code which gives me the error 91:



Sub InsertLabelnameBubble()
ActiveChart.FullSeriesCollection(1).DataLabels.Select

For i = 1 To Range("Table").Rows.Count
ActiveChart.FullSeriesCollection(1).Points(i).DataLabel.Select
Selection.Formula = Range("Table").Cells(i, 1)
Next i
End Sub


Here's a screenshot of my project.



Screenshot 1



Where you can see that it uses the Y column (Expected project potential) as the data label text. What I would like it to do is that it should take it from the first column in my table (Project #).










share|improve this question




















  • 3




    Maybe include some screen shots. Doesn't seem clear what you're asking for.
    – PGCodeRider
    Oct 31 at 14:28






  • 1




    Also, which line are you receiving the error? Error 91 means you are trying to use an object set to Nothing
    – Kubie
    Oct 31 at 14:33






  • 2




    See The VBA Guide To ListObject Excel Tables for how to properly access a table in Excel VBA. You must probably use something like ActiveSheet.ListObjects("Table").DataBodyRange(i, 1)
    – Pᴇʜ
    Oct 31 at 14:41












  • Am I allowed to upload my project file somewhere and post the link here? I'm not sure a screenshot is enough, and I'm really searching for a solution, which should be included in my Master's thesis.
    – Rasmus Holt Hansen
    Nov 1 at 11:19










  • You could manually link your labels to cells. Use a formula to pull the correct project name into a specific cell and then click your label twice before selecting the formula bar and then your cell. John Peltier explains it on his site - third heading.
    – Darren Bartrup-Cook
    Nov 5 at 14:17













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have an Excel worksheet with a table that contains columns for project name, x, y, size in order to create a bubble graph.



I would like it to change the Data labels to be equal to the respective project name but how do I do that? I've searched on the web for solutions but neither of them with succes.



Here's my data:




  • Chart name: Chart 1

  • Table name: Table (This one have headers and I'm
    only searching for the range within the table (data body range).


Here's my code which gives me the error 91:



Sub InsertLabelnameBubble()
ActiveChart.FullSeriesCollection(1).DataLabels.Select

For i = 1 To Range("Table").Rows.Count
ActiveChart.FullSeriesCollection(1).Points(i).DataLabel.Select
Selection.Formula = Range("Table").Cells(i, 1)
Next i
End Sub


Here's a screenshot of my project.



Screenshot 1



Where you can see that it uses the Y column (Expected project potential) as the data label text. What I would like it to do is that it should take it from the first column in my table (Project #).










share|improve this question















I have an Excel worksheet with a table that contains columns for project name, x, y, size in order to create a bubble graph.



I would like it to change the Data labels to be equal to the respective project name but how do I do that? I've searched on the web for solutions but neither of them with succes.



Here's my data:




  • Chart name: Chart 1

  • Table name: Table (This one have headers and I'm
    only searching for the range within the table (data body range).


Here's my code which gives me the error 91:



Sub InsertLabelnameBubble()
ActiveChart.FullSeriesCollection(1).DataLabels.Select

For i = 1 To Range("Table").Rows.Count
ActiveChart.FullSeriesCollection(1).Points(i).DataLabel.Select
Selection.Formula = Range("Table").Cells(i, 1)
Next i
End Sub


Here's a screenshot of my project.



Screenshot 1



Where you can see that it uses the Y column (Expected project potential) as the data label text. What I would like it to do is that it should take it from the first column in my table (Project #).







excel vba excel-vba range bubble-chart






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 5 at 10:36









Pᴇʜ

19.8k42650




19.8k42650










asked Oct 31 at 14:24









Rasmus Holt Hansen

11




11








  • 3




    Maybe include some screen shots. Doesn't seem clear what you're asking for.
    – PGCodeRider
    Oct 31 at 14:28






  • 1




    Also, which line are you receiving the error? Error 91 means you are trying to use an object set to Nothing
    – Kubie
    Oct 31 at 14:33






  • 2




    See The VBA Guide To ListObject Excel Tables for how to properly access a table in Excel VBA. You must probably use something like ActiveSheet.ListObjects("Table").DataBodyRange(i, 1)
    – Pᴇʜ
    Oct 31 at 14:41












  • Am I allowed to upload my project file somewhere and post the link here? I'm not sure a screenshot is enough, and I'm really searching for a solution, which should be included in my Master's thesis.
    – Rasmus Holt Hansen
    Nov 1 at 11:19










  • You could manually link your labels to cells. Use a formula to pull the correct project name into a specific cell and then click your label twice before selecting the formula bar and then your cell. John Peltier explains it on his site - third heading.
    – Darren Bartrup-Cook
    Nov 5 at 14:17














  • 3




    Maybe include some screen shots. Doesn't seem clear what you're asking for.
    – PGCodeRider
    Oct 31 at 14:28






  • 1




    Also, which line are you receiving the error? Error 91 means you are trying to use an object set to Nothing
    – Kubie
    Oct 31 at 14:33






  • 2




    See The VBA Guide To ListObject Excel Tables for how to properly access a table in Excel VBA. You must probably use something like ActiveSheet.ListObjects("Table").DataBodyRange(i, 1)
    – Pᴇʜ
    Oct 31 at 14:41












  • Am I allowed to upload my project file somewhere and post the link here? I'm not sure a screenshot is enough, and I'm really searching for a solution, which should be included in my Master's thesis.
    – Rasmus Holt Hansen
    Nov 1 at 11:19










  • You could manually link your labels to cells. Use a formula to pull the correct project name into a specific cell and then click your label twice before selecting the formula bar and then your cell. John Peltier explains it on his site - third heading.
    – Darren Bartrup-Cook
    Nov 5 at 14:17








3




3




Maybe include some screen shots. Doesn't seem clear what you're asking for.
– PGCodeRider
Oct 31 at 14:28




Maybe include some screen shots. Doesn't seem clear what you're asking for.
– PGCodeRider
Oct 31 at 14:28




1




1




Also, which line are you receiving the error? Error 91 means you are trying to use an object set to Nothing
– Kubie
Oct 31 at 14:33




Also, which line are you receiving the error? Error 91 means you are trying to use an object set to Nothing
– Kubie
Oct 31 at 14:33




2




2




See The VBA Guide To ListObject Excel Tables for how to properly access a table in Excel VBA. You must probably use something like ActiveSheet.ListObjects("Table").DataBodyRange(i, 1)
– Pᴇʜ
Oct 31 at 14:41






See The VBA Guide To ListObject Excel Tables for how to properly access a table in Excel VBA. You must probably use something like ActiveSheet.ListObjects("Table").DataBodyRange(i, 1)
– Pᴇʜ
Oct 31 at 14:41














Am I allowed to upload my project file somewhere and post the link here? I'm not sure a screenshot is enough, and I'm really searching for a solution, which should be included in my Master's thesis.
– Rasmus Holt Hansen
Nov 1 at 11:19




Am I allowed to upload my project file somewhere and post the link here? I'm not sure a screenshot is enough, and I'm really searching for a solution, which should be included in my Master's thesis.
– Rasmus Holt Hansen
Nov 1 at 11:19












You could manually link your labels to cells. Use a formula to pull the correct project name into a specific cell and then click your label twice before selecting the formula bar and then your cell. John Peltier explains it on his site - third heading.
– Darren Bartrup-Cook
Nov 5 at 14:17




You could manually link your labels to cells. Use a formula to pull the correct project name into a specific cell and then click your label twice before selecting the formula bar and then your cell. John Peltier explains it on his site - third heading.
– Darren Bartrup-Cook
Nov 5 at 14:17












2 Answers
2






active

oldest

votes

















up vote
0
down vote













This is code that I use for data labels from a range. Have found this on stackoverflow a while back:



Sub DataLables 
Dim ws as worksheet, DataLR As Series, pts As Points, pt As Point, rngLabels As Range, IDi As Integer, ChtObj As ChartObject
Set ws = ActiveWorkbook.ActiveSheet

With ws
Set ChtObj = .ChartObjects("ChatName")
Set rngLabels = .Range("A5:A39")
Set DataLR = ChtObj.Chart.SeriesCollection(2)
DataLR.HasDataLabels = True
For Each pt In pts
IDi = IDi + 1
pt.DataLabel.Text = rngLabels.Cells(IDi).Text
pt.DataLabel.Font.Bold = True
Next pt
End With

End Sub


Let me know if this helps. It will update the data labels with the values in the range.






share|improve this answer























  • I'm not sure whether I'm doing it wrong or not, but I keep receiving the error: "Object variable or With block variable not set".. I have you copied your code into the worksheet macro, changed the chart name and the range to match, and placed a button to trigger the macro. What does this mean?
    – Rasmus Holt Hansen
    Nov 1 at 8:31










  • This should work. Please let m know if you still have issues. Thank you.
    – Bojan Goldy
    Nov 6 at 13:55










  • So now my vba looks like this, where I'm receiving an error ( ) in the marked line. Set ChtObj = .ChartObjects("Chart 1") Set rngLabels = .Range("Table1[Project '#]") Set DataLR = ChtObj.Chart.SeriesCollection(1) DataLR.HasDataLabels = True For Each pt In pts ' <--- Run-time error 424: Object required IDi = IDi + 1 pt.DataLabel.Text = rngLabels.Cells(IDi).Text pt.DataLabel.Font.Bold = True Next pt End With End Sub Also my range should not include the header (Set rngLabels) so how to achieve this as well?
    – Rasmus Holt Hansen
    Nov 7 at 10:01












  • .Range("A5:A39") - you need to update the range and specify the fist one you would like to take
    – Bojan Goldy
    Nov 7 at 14:43












  • I've tried that but I'm still receiving an error in the "For Each pt in pts": 424: Object required.
    – Rasmus Holt Hansen
    Nov 12 at 8:54


















up vote
0
down vote



accepted










So I did find the solution myself. Here's my final code inserting labels from the Table into the Bubble Chart:



Sub DataLables()

ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.FullSeriesCollection(1).DataLabels.Select

For i = 1 To Range("Table1[Project '#]").Count

ActiveChart.FullSeriesCollection(1).Points(i).DataLabel.Select

Selection.Formula = Range("Table1[Project '#]").Cells(i, 1)

Next i

End Sub





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53085660%2fexcel-vba-add-data-labels-from-table-body-range%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    This is code that I use for data labels from a range. Have found this on stackoverflow a while back:



    Sub DataLables 
    Dim ws as worksheet, DataLR As Series, pts As Points, pt As Point, rngLabels As Range, IDi As Integer, ChtObj As ChartObject
    Set ws = ActiveWorkbook.ActiveSheet

    With ws
    Set ChtObj = .ChartObjects("ChatName")
    Set rngLabels = .Range("A5:A39")
    Set DataLR = ChtObj.Chart.SeriesCollection(2)
    DataLR.HasDataLabels = True
    For Each pt In pts
    IDi = IDi + 1
    pt.DataLabel.Text = rngLabels.Cells(IDi).Text
    pt.DataLabel.Font.Bold = True
    Next pt
    End With

    End Sub


    Let me know if this helps. It will update the data labels with the values in the range.






    share|improve this answer























    • I'm not sure whether I'm doing it wrong or not, but I keep receiving the error: "Object variable or With block variable not set".. I have you copied your code into the worksheet macro, changed the chart name and the range to match, and placed a button to trigger the macro. What does this mean?
      – Rasmus Holt Hansen
      Nov 1 at 8:31










    • This should work. Please let m know if you still have issues. Thank you.
      – Bojan Goldy
      Nov 6 at 13:55










    • So now my vba looks like this, where I'm receiving an error ( ) in the marked line. Set ChtObj = .ChartObjects("Chart 1") Set rngLabels = .Range("Table1[Project '#]") Set DataLR = ChtObj.Chart.SeriesCollection(1) DataLR.HasDataLabels = True For Each pt In pts ' <--- Run-time error 424: Object required IDi = IDi + 1 pt.DataLabel.Text = rngLabels.Cells(IDi).Text pt.DataLabel.Font.Bold = True Next pt End With End Sub Also my range should not include the header (Set rngLabels) so how to achieve this as well?
      – Rasmus Holt Hansen
      Nov 7 at 10:01












    • .Range("A5:A39") - you need to update the range and specify the fist one you would like to take
      – Bojan Goldy
      Nov 7 at 14:43












    • I've tried that but I'm still receiving an error in the "For Each pt in pts": 424: Object required.
      – Rasmus Holt Hansen
      Nov 12 at 8:54















    up vote
    0
    down vote













    This is code that I use for data labels from a range. Have found this on stackoverflow a while back:



    Sub DataLables 
    Dim ws as worksheet, DataLR As Series, pts As Points, pt As Point, rngLabels As Range, IDi As Integer, ChtObj As ChartObject
    Set ws = ActiveWorkbook.ActiveSheet

    With ws
    Set ChtObj = .ChartObjects("ChatName")
    Set rngLabels = .Range("A5:A39")
    Set DataLR = ChtObj.Chart.SeriesCollection(2)
    DataLR.HasDataLabels = True
    For Each pt In pts
    IDi = IDi + 1
    pt.DataLabel.Text = rngLabels.Cells(IDi).Text
    pt.DataLabel.Font.Bold = True
    Next pt
    End With

    End Sub


    Let me know if this helps. It will update the data labels with the values in the range.






    share|improve this answer























    • I'm not sure whether I'm doing it wrong or not, but I keep receiving the error: "Object variable or With block variable not set".. I have you copied your code into the worksheet macro, changed the chart name and the range to match, and placed a button to trigger the macro. What does this mean?
      – Rasmus Holt Hansen
      Nov 1 at 8:31










    • This should work. Please let m know if you still have issues. Thank you.
      – Bojan Goldy
      Nov 6 at 13:55










    • So now my vba looks like this, where I'm receiving an error ( ) in the marked line. Set ChtObj = .ChartObjects("Chart 1") Set rngLabels = .Range("Table1[Project '#]") Set DataLR = ChtObj.Chart.SeriesCollection(1) DataLR.HasDataLabels = True For Each pt In pts ' <--- Run-time error 424: Object required IDi = IDi + 1 pt.DataLabel.Text = rngLabels.Cells(IDi).Text pt.DataLabel.Font.Bold = True Next pt End With End Sub Also my range should not include the header (Set rngLabels) so how to achieve this as well?
      – Rasmus Holt Hansen
      Nov 7 at 10:01












    • .Range("A5:A39") - you need to update the range and specify the fist one you would like to take
      – Bojan Goldy
      Nov 7 at 14:43












    • I've tried that but I'm still receiving an error in the "For Each pt in pts": 424: Object required.
      – Rasmus Holt Hansen
      Nov 12 at 8:54













    up vote
    0
    down vote










    up vote
    0
    down vote









    This is code that I use for data labels from a range. Have found this on stackoverflow a while back:



    Sub DataLables 
    Dim ws as worksheet, DataLR As Series, pts As Points, pt As Point, rngLabels As Range, IDi As Integer, ChtObj As ChartObject
    Set ws = ActiveWorkbook.ActiveSheet

    With ws
    Set ChtObj = .ChartObjects("ChatName")
    Set rngLabels = .Range("A5:A39")
    Set DataLR = ChtObj.Chart.SeriesCollection(2)
    DataLR.HasDataLabels = True
    For Each pt In pts
    IDi = IDi + 1
    pt.DataLabel.Text = rngLabels.Cells(IDi).Text
    pt.DataLabel.Font.Bold = True
    Next pt
    End With

    End Sub


    Let me know if this helps. It will update the data labels with the values in the range.






    share|improve this answer














    This is code that I use for data labels from a range. Have found this on stackoverflow a while back:



    Sub DataLables 
    Dim ws as worksheet, DataLR As Series, pts As Points, pt As Point, rngLabels As Range, IDi As Integer, ChtObj As ChartObject
    Set ws = ActiveWorkbook.ActiveSheet

    With ws
    Set ChtObj = .ChartObjects("ChatName")
    Set rngLabels = .Range("A5:A39")
    Set DataLR = ChtObj.Chart.SeriesCollection(2)
    DataLR.HasDataLabels = True
    For Each pt In pts
    IDi = IDi + 1
    pt.DataLabel.Text = rngLabels.Cells(IDi).Text
    pt.DataLabel.Font.Bold = True
    Next pt
    End With

    End Sub


    Let me know if this helps. It will update the data labels with the values in the range.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 7 at 15:38

























    answered Oct 31 at 15:18









    Bojan Goldy

    12




    12












    • I'm not sure whether I'm doing it wrong or not, but I keep receiving the error: "Object variable or With block variable not set".. I have you copied your code into the worksheet macro, changed the chart name and the range to match, and placed a button to trigger the macro. What does this mean?
      – Rasmus Holt Hansen
      Nov 1 at 8:31










    • This should work. Please let m know if you still have issues. Thank you.
      – Bojan Goldy
      Nov 6 at 13:55










    • So now my vba looks like this, where I'm receiving an error ( ) in the marked line. Set ChtObj = .ChartObjects("Chart 1") Set rngLabels = .Range("Table1[Project '#]") Set DataLR = ChtObj.Chart.SeriesCollection(1) DataLR.HasDataLabels = True For Each pt In pts ' <--- Run-time error 424: Object required IDi = IDi + 1 pt.DataLabel.Text = rngLabels.Cells(IDi).Text pt.DataLabel.Font.Bold = True Next pt End With End Sub Also my range should not include the header (Set rngLabels) so how to achieve this as well?
      – Rasmus Holt Hansen
      Nov 7 at 10:01












    • .Range("A5:A39") - you need to update the range and specify the fist one you would like to take
      – Bojan Goldy
      Nov 7 at 14:43












    • I've tried that but I'm still receiving an error in the "For Each pt in pts": 424: Object required.
      – Rasmus Holt Hansen
      Nov 12 at 8:54


















    • I'm not sure whether I'm doing it wrong or not, but I keep receiving the error: "Object variable or With block variable not set".. I have you copied your code into the worksheet macro, changed the chart name and the range to match, and placed a button to trigger the macro. What does this mean?
      – Rasmus Holt Hansen
      Nov 1 at 8:31










    • This should work. Please let m know if you still have issues. Thank you.
      – Bojan Goldy
      Nov 6 at 13:55










    • So now my vba looks like this, where I'm receiving an error ( ) in the marked line. Set ChtObj = .ChartObjects("Chart 1") Set rngLabels = .Range("Table1[Project '#]") Set DataLR = ChtObj.Chart.SeriesCollection(1) DataLR.HasDataLabels = True For Each pt In pts ' <--- Run-time error 424: Object required IDi = IDi + 1 pt.DataLabel.Text = rngLabels.Cells(IDi).Text pt.DataLabel.Font.Bold = True Next pt End With End Sub Also my range should not include the header (Set rngLabels) so how to achieve this as well?
      – Rasmus Holt Hansen
      Nov 7 at 10:01












    • .Range("A5:A39") - you need to update the range and specify the fist one you would like to take
      – Bojan Goldy
      Nov 7 at 14:43












    • I've tried that but I'm still receiving an error in the "For Each pt in pts": 424: Object required.
      – Rasmus Holt Hansen
      Nov 12 at 8:54
















    I'm not sure whether I'm doing it wrong or not, but I keep receiving the error: "Object variable or With block variable not set".. I have you copied your code into the worksheet macro, changed the chart name and the range to match, and placed a button to trigger the macro. What does this mean?
    – Rasmus Holt Hansen
    Nov 1 at 8:31




    I'm not sure whether I'm doing it wrong or not, but I keep receiving the error: "Object variable or With block variable not set".. I have you copied your code into the worksheet macro, changed the chart name and the range to match, and placed a button to trigger the macro. What does this mean?
    – Rasmus Holt Hansen
    Nov 1 at 8:31












    This should work. Please let m know if you still have issues. Thank you.
    – Bojan Goldy
    Nov 6 at 13:55




    This should work. Please let m know if you still have issues. Thank you.
    – Bojan Goldy
    Nov 6 at 13:55












    So now my vba looks like this, where I'm receiving an error ( ) in the marked line. Set ChtObj = .ChartObjects("Chart 1") Set rngLabels = .Range("Table1[Project '#]") Set DataLR = ChtObj.Chart.SeriesCollection(1) DataLR.HasDataLabels = True For Each pt In pts ' <--- Run-time error 424: Object required IDi = IDi + 1 pt.DataLabel.Text = rngLabels.Cells(IDi).Text pt.DataLabel.Font.Bold = True Next pt End With End Sub Also my range should not include the header (Set rngLabels) so how to achieve this as well?
    – Rasmus Holt Hansen
    Nov 7 at 10:01






    So now my vba looks like this, where I'm receiving an error ( ) in the marked line. Set ChtObj = .ChartObjects("Chart 1") Set rngLabels = .Range("Table1[Project '#]") Set DataLR = ChtObj.Chart.SeriesCollection(1) DataLR.HasDataLabels = True For Each pt In pts ' <--- Run-time error 424: Object required IDi = IDi + 1 pt.DataLabel.Text = rngLabels.Cells(IDi).Text pt.DataLabel.Font.Bold = True Next pt End With End Sub Also my range should not include the header (Set rngLabels) so how to achieve this as well?
    – Rasmus Holt Hansen
    Nov 7 at 10:01














    .Range("A5:A39") - you need to update the range and specify the fist one you would like to take
    – Bojan Goldy
    Nov 7 at 14:43






    .Range("A5:A39") - you need to update the range and specify the fist one you would like to take
    – Bojan Goldy
    Nov 7 at 14:43














    I've tried that but I'm still receiving an error in the "For Each pt in pts": 424: Object required.
    – Rasmus Holt Hansen
    Nov 12 at 8:54




    I've tried that but I'm still receiving an error in the "For Each pt in pts": 424: Object required.
    – Rasmus Holt Hansen
    Nov 12 at 8:54












    up vote
    0
    down vote



    accepted










    So I did find the solution myself. Here's my final code inserting labels from the Table into the Bubble Chart:



    Sub DataLables()

    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.FullSeriesCollection(1).DataLabels.Select

    For i = 1 To Range("Table1[Project '#]").Count

    ActiveChart.FullSeriesCollection(1).Points(i).DataLabel.Select

    Selection.Formula = Range("Table1[Project '#]").Cells(i, 1)

    Next i

    End Sub





    share|improve this answer

























      up vote
      0
      down vote



      accepted










      So I did find the solution myself. Here's my final code inserting labels from the Table into the Bubble Chart:



      Sub DataLables()

      ActiveSheet.ChartObjects("Chart 1").Activate
      ActiveChart.FullSeriesCollection(1).DataLabels.Select

      For i = 1 To Range("Table1[Project '#]").Count

      ActiveChart.FullSeriesCollection(1).Points(i).DataLabel.Select

      Selection.Formula = Range("Table1[Project '#]").Cells(i, 1)

      Next i

      End Sub





      share|improve this answer























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        So I did find the solution myself. Here's my final code inserting labels from the Table into the Bubble Chart:



        Sub DataLables()

        ActiveSheet.ChartObjects("Chart 1").Activate
        ActiveChart.FullSeriesCollection(1).DataLabels.Select

        For i = 1 To Range("Table1[Project '#]").Count

        ActiveChart.FullSeriesCollection(1).Points(i).DataLabel.Select

        Selection.Formula = Range("Table1[Project '#]").Cells(i, 1)

        Next i

        End Sub





        share|improve this answer












        So I did find the solution myself. Here's my final code inserting labels from the Table into the Bubble Chart:



        Sub DataLables()

        ActiveSheet.ChartObjects("Chart 1").Activate
        ActiveChart.FullSeriesCollection(1).DataLabels.Select

        For i = 1 To Range("Table1[Project '#]").Count

        ActiveChart.FullSeriesCollection(1).Points(i).DataLabel.Select

        Selection.Formula = Range("Table1[Project '#]").Cells(i, 1)

        Next i

        End Sub






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 at 8:56









        Rasmus Holt Hansen

        11




        11






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53085660%2fexcel-vba-add-data-labels-from-table-body-range%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            What visual should I use to simply compare current year value vs last year in Power BI desktop

            How to ignore python UserWarning in pytest?

            Alexandru Averescu