我已经编写了一个代码,可以根据输入框中输入的内容将图表扩展一定的范围。但是,我现在要改变它,因为现在不是通过Rng_Extension扩展EndPoint而是现在的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
答案 0 :(得分:0)
简单并完成工作。感谢你们! 只是一个提示: EndPoint = Range(EndPoint).Offset(0,Rng_Extension).Address添加新数据的COLUMNS,而 EndPoint = Range(EndPoint)。Offset(Rng_Extension,0).Address添加新数据的ROWS