▽1
●
Silvanus ベストアンサー |
マクロを使っても良いのであれば、こんな感じでいかがでしょうか。
エラー処理も何も施していない、芸の無い代物ですが…。
Option Explicit Option Base 0 Sub AddChargeStepGraph_dankan() Dim rngSrc As Range Dim intCnS As Integer Dim intCnD As Integer Dim intNoS As Integer Dim intNoD As Integer Dim arrDtX() As Variant Dim arrDtY() As Variant Set rngSrc = Selection intNoS = rngSrc.Rows.Count - 1 intNoD = rngSrc.Columns.Count - 1 ReDim arrDtX(intNoD * 2) As Variant ReDim arrDtY(intNoD * 2) As Variant ActiveSheet.Shapes.AddChart.Select With ActiveChart .ChartType = xlXYScatterLinesNoMarkers .SetSourceData Source:=rngSrc .SetElement (msoElementChartTitleAboveChart) .SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis) .SetElement (msoElementPrimaryValueAxisTitleRotated) .ChartTitle.Text = WorksheetFunction.Index(rngSrc, 1, 1) .Axes(xlCategory).AxisTitle.Text = "人数" .Axes(xlValue, xlPrimary).AxisTitle.Text = "料金" For intCnS = 1 To intNoS With .SeriesCollection(intCnS) arrDtX(0) = 0 arrDtY(0) = 0 For intCnD = 1 To intNoD arrDtX(intCnD * 2 - 1) = _ WorksheetFunction.Index( _ rngSrc, 1, 1 + intCnD) arrDtY(intCnD * 2 - 1) = _ arrDtY(intCnD * 2 - 2) arrDtX(intCnD * 2) = _ arrDtX(intCnD * 2 - 1) arrDtY(intCnD * 2) = _ WorksheetFunction.Index( _ rngSrc, 1 + intCnS, 1 + intCnD) Next .XValues = arrDtX .Values = arrDtY End With Next End With rngSrc.Select End Sub
【使い方】
1. ご質問文の中に書かれていた様な形式の表を用意する。
・一行目が人数、二行目以降は料金プラン
・二行目以降の最左列は料金プラン名
・一行目の最左列はグラフ名になる様にしました
2. 下図の様に表を選択する。
3. 上記のマクロ「AddChargeStepGraph_dankan」を実行する。
この方式では、作成された「グラフ」と「料金表(セルの数値)」の
リンクは切れていますので、料金表の数値を変更したり
表そのものを削除する等しても、グラフには変化はありません。
当方はExcel2010上でマクロを作成し、Excel98-2003互換形式(.xls)で
保存する際に注意・警告メッセージが出ないことを確認しましたので
恐らくExcel2003上でも動くと思うのですが
もし期待通りに動作しない場合はその旨お知らせ下さい。