charts - Add data labels to the last point in a series in excel -
i have around 50 charts in excel worksheet should update every month. need vba code add data labels last point in data series, charts in worksheet. each chart has 3 series, need add labels month's data(latest point) 1 series ytd amount. have no knowledge in writing vba code. have seen couple codes , tried copying , making small changes, no code suits requirement. don't want make 50+ changes every month manually, thing address issue helpful. appreciate help!
something ought started:
option explicit private sub addlabelslastpoint() dim ch chartobject 'loop through each chart object each ch in worksheets("sheet3").chartobjects 'grab final series of chart ch.chart.seriescollection(3) 'apply data label final point in series .points(.points.count).applydatalabels end next ch end sub
open vb editor alt+f11 (or go developer --> visual basic on ribbon) , right click 'microsoft excel objects' --> insert --> module
be sure change worksheets("sheet3")
whichever worksheet using. additionally, code assumes ytd amount last series, hence seriescollection(3)
of each chart. if isn't case, need modify code, starting point @ least.
since have no knowledge of writing vba, point out 2 other things (which irrelevant problem, know nonetheless).
first option explicit
keyboard. forces variables declared before can used. practice include in vba code. if don't include this, may unexpected results (if, example, misspell variable name).
second private
keyword. means code within current module can access subroutine.
Comments
Post a Comment