折れ線グラフの一番右にデータラベルをつけるExcelマクロ
https://gyazo.com/a10711adfad6f3410db525689683a944
code:vb
Sub AddLegendLabelToRight()
Dim ChartSeriesCount As Long
Dim PontCount As Long
Dim ChartPoint
If ActiveChart Is Nothing Then _
MsgBox "Select a chart and try again.", , "Select Chart": GoTo End_Sub
On Error Resume Next
ChartSeriesCount = ActiveChart.SeriesCollection.Count
ActiveChart.PlotArea.Width = ActiveChart.PlotArea.Width * 0.9
ActiveChart.PlotArea.Left = (ActiveChart.Parent.Width - ActiveChart.PlotArea.Width) / 2
Dim SeriesId As Integer
For SeriesId = 1 To ChartSeriesCount
PointCount = ActiveChart.FullSeriesCollection(SeriesId).Points.Count
Set ChartPoint = ActiveChart.FullSeriesCollection(SeriesId).Points(PointCount)
ChartPoint.Select
ActiveChart.SetElement (msoElementDataLabelRight)
ChartPoint.ApplyDataLabels
ChartPoint.DataLabel.ShowValue = 0
ChartPoint.DataLabel.ShowSeriesName = -1
Next
End_Sub:
End Sub