excel - Macro to select last data point in line chart and add a data label -


i have line chart 60 different data series in excel updates once week. in chart, program macro selects recent data points in line charts , adds data label in format 100.00 (number 2 decimal places).

i using code below delete data labels:

sub delete_labels()  activechart.applydatalabels xldatalabelsshownone  end sub 

to add data labels, use code well. have been experimenting code below:

sub add_last_label()  activechart.applydatalabels xldatalabelsshowlabel, , , , true, false, false, false, false  end sub 

however, code adds data labels each data point, creating huge mess. string ", , , , true, false, false, false, false" must adapted add last data label in chart, unsure how.

does have idea how data labels last point in each series in format 100.00 (with 2 decimal points)?

i found answer. code below works:

sub update_labels()  activechart.applydatalabels xldatalabelsshownone  dim isrs long dim ipts long isrs = 1 activechart.seriescollection.count activechart.seriescollection(isrs) ipts = .points.count .points(ipts) .applydatalabels ' .datalabel.showseriesname = -1 ' .datalabel.showlegendkey = -1  .datalabel.numberformat = "#,##0.00"  'activechart.seriescollection(1).datalabels.numberformat = "#,##0.00"  end end next  end sub 

uncomment showseriesname , showlegendkey show items.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -