0
この問題は数回説明されていますが、例を見てみると、ここで何が問題なのか正確に把握できませんでした。 解決済み:Excel-VBA ActiveChart.FullSeriesCollection.Nameがセルにリンクしていません
ActiveChart.FullSeriesCollection(1).Name = "='GSI with DSPV Data'!$BUX$4"
ActiveChart.FullSeriesCollection(1).Name = Worksheets("GSI with DSPV Data").Cells(nameRow, nameCol)
nameRow
とnameCol
以下は、新しいシリーズの名前を作成するための2つの例です。どちらの場合も、凡例には新しいシリーズ名が正しく表示されます。ただし、2番目の例では、セルを系列名GUIエディットボックスにリンクしていません。シリーズ名ボックスは空白のままです。
最初の例は、繰り返しのForループ内にあるため、列と行の変数を使用してセルを表す必要があるため、私にとっては役に立ちません。
私の完全なコードは以下を参照してください:
Sub ExtendPlot()
Dim nameRow As Integer
Dim nameCol As Integer
Dim maxPlotRow As Integer
Dim xPlotCol As Integer
Dim minPlotRow As Integer
Dim yPlotCol As Integer
Dim xValues As Range
Dim yValues As Range
nameRow = 4 'the series name is always on the same row
minPlotRow = 2 'the minimum plotted row is always 2
maxPlotRow = 400 'the maximum plotted row is always 400
nameCol = Sheets("GSI with DSPV Data").Columns("BUX").Column 'specify the column of the series name location and turn this into an integer
xPlotCol = Sheets("GSI with DSPV Data").Columns("BUY").Column 'specify the column of the series x values location and turn this into an integer
yPlotCol = Sheets("GSI with DSPV Data").Columns("BUZ").Column 'specify the column of the series y values location and turn this into an integer
Set xValues = Range(Sheets("GSI with DSPV Data").Cells(minPlotRow, xPlotCol), Sheets("GSI with DSPV Data").Cells(maxPlotRow, xPlotCol)) 'set the range of the x axis given the above values
Set yValues = Range(Sheets("GSI with DSPV Data").Cells(minPlotRow, yPlotCol), Sheets("GSI with DSPV Data").Cells(maxPlotRow, yPlotCol)) 'set the range of the y axis given the above values
ActiveChart.SeriesCollection.NewSeries 'create a new series on the current graph
ActiveChart.FullSeriesCollection(1).Name = "='GSI with DSPV Data'!$BUX$4" 'create the name for the new series by linking to the reference cell
ActiveChart.FullSeriesCollection(1).xValues = xValues 'create the x axis by linking to the x axis range
ActiveChart.FullSeriesCollection(1).Values = yValues 'create the y axis by linking to the y axis range
For i = 2 To 30 'start a For loop for the next coming series
nameCol = nameCol + 8 'the name of the next series is always located 8 columns later than the first
xPlotCol = xPlotCol + 8 'the x axis values of the next series are always located 8 columns later than the first
yPlotCol = yPlotCol + 8 'the y axis values of the next series are always located 8 columns later than the first
Set xValues = Range(Sheets("GSI with DSPV Data").Cells(minPlotRow, xPlotCol), Sheets("GSI with DSPV Data").Cells(maxPlotRow, xPlotCol)) 'set the range of the x axis given the above values
Set yValues = Range(Sheets("GSI with DSPV Data").Cells(minPlotRow, yPlotCol), Sheets("GSI with DSPV Data").Cells(maxPlotRow, yPlotCol)) 'set the range of the y axis given the above values
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(i).Name = Worksheets("GSI with DSPV Data").Cells(nameRow, nameCol) 'create the name for the new series by linking to the reference cell
ActiveChart.FullSeriesCollection(i).xValues = xValues 'create the x axis by linking to the x axis range
ActiveChart.FullSeriesCollection(i).Values = yValues 'create the y axis by linking to the y axis range
Next i
End Sub
私はゼロVBAの経験を持つ人々がここに起こっているまさに想像できるように、意図的にx軸とy軸に別々の範囲を使用しています。これを行うには、計算上の網羅的なものではありません(私は思っていませんか?)。それはちょうど非常にきれいに見えません。
これに関するお手伝いがあれば幸いです。
下記の方法でそれをしようとしてについてどのように
は助けをありがとうございました。私はあなたが提案したものを実装し、それがうまくいった。 しかし、1つのこと、私はWithループの必要性を見ていないのですか?そのポイントは何ですか? –
@MichaelWhitakerコーディングのちょうど私のスタイル、あなたはそれを取り除くことができます –
確かに十分な公正。これは助けてくれてありがとう。 これはなぜ必要なのかご存知ですか? たとえば、理由は: ActiveChart.FullSeriesCollection(i).Name =ワークシート(「DSPVデータを含むGSI」)セル(nameRow、nameCol) は機能しません。私はこのタイプのコマンドがヘッダを選択しないので、動作しないと言われたことを覚えています。私はこれが何を意味するのか全く分かりません。 –