入力ボックスに何が置かれているかによって、特定の範囲でグラフを拡張するためのコードを記述しました。しかし、Rng_ExtensionでEndPointを拡張するのではなく、StartPointを今すぐ変更する予定です。しかし、私はそれを変更するときMacro StartPointでの範囲拡張の問題
ser.Values = StartPoint & ":" & EndPoint
と
ser.XValues = StartPoint & ":" & EndPoint
それが何らかの理由で両者を組み合わせることはできませんと一部でのエラーがあります。誰も助けることができますか?
Sub Chart_Extender()
Dim Rng_Extension As Integer
Dim Series_Formula As String
Dim StartPoint As String
Dim EndPoint As String
Dim CommaSplit As Variant
Dim ColonSplit As Variant
Dim grph As ChartObject
Dim ser As Series
On Error GoTo BadEntry
Rng_Extension = InputBox(_
"How many cells do you want to extend your chart's series?", _
"Chart Extender")
On Error GoTo 0
For Each grph In ActiveSheet.ChartObjects
For Each ser In grph.Chart.SeriesCollection
If ser.NAME = "ACTUALS" Then
Exit For
End If
If ser.ChartType <> 75 Then
'Get range of series
Series_Formula = ser.Formula
'X Axis Values
CommaSplit = Split(Series_Formula, ",") 'Delimit by comma
ColonSplit = Split(CommaSplit(2), ":") 'Delimit 3rd part by colon
StartPoint = ColonSplit(0) 'Starting Point of Range
EndPoint = ColonSplit(1) 'Current Ending Point Range
EndPoint = Range(EndPoint).Offset(0, Rng_Extension).Address 'Extended Ending Point Range
ser.Values = StartPoint & ":" & EndPoint 'Combine Start and End Point & Set Series = To It
'X Axis Labels
If CommaSplit(1) <> "" Then
ColonSplit = Split(CommaSplit(1), ":") 'Delimit 3rd part by colon
StartPoint = ColonSplit(0) 'Starting Point of Range
EndPoint = ColonSplit(1) 'Current Ending Point Range
EndPoint = Range(EndPoint).Offset(0, Rng_Extension).Address 'Extended Ending Point Range
ser.XValues = StartPoint & ":" & EndPoint 'Combine Start and End Point & Set Series = To It
End If
End If
Next ser
Next grph
'Completion Message
MsgBox "Your chart has been Extended by " & Rng_Extension & " positions."
Exit Sub
'Error Handling
BadEntry:
MsgBox "Your input must be a whole number, aborting", vbCritical, "Improper Entry"
End Sub
'EndPoint = Range(EndPoint).Offset ...'の後、次の行に 'Debug.Print" StartPoint = "&StartPoint&CHR(10)&" EndPoint = "&EndPoint'を入力します。 'ser.Value = ....'行に改行を入れ、コードを実行してください。中間ウィンドウに開始点と終了点が表示されます。彼らはあなたが期待しているものですか? – Tyeler
@Tyelerはい値は私がそれらになると思います。たとえば、私が変更した場合 EndPoint = Range(EndtPoint).Offset(0、Rng_Extension).Address to StartPoint =範囲(StartPoint).Offset(0、Rng_Extension).Address ser.Values改行はそれらを結合しませんSeries_Formulaに戻します。何かご意見は? – ExcelMonkey19
まあ、私は 'シリーズ'についてたくさん知っているわけではありませんが、[MSDN doc](https://msdn.microsoft.com/en-us/library/office/ff197014.aspx)によると、 'ser.Values = ActiveSheet.Range(StartPoint&": "&EndPoint)'に変更してみてください。私はそれを読んだのですか? – Tyeler