[英]How to extend the range that is included in a graph with a macro
這對我有用:
Sub ExpandChartSource()
Dim ObjChart As Object
Dim RngSource As Range
Set ObjChart = ActiveSheet.ChartObjects(1)
Set RngSource = Range(Split(ObjChart.Chart.SeriesCollection(1).Formula, ",")(2))
Set RngSource = RngSource.Resize(RngSource.Rows.Count, RngSource.Columns.Count + 1)
ObjChart.Chart.SetSourceData Source:=RngSource
End Sub
這里有一個更動態的版本,如果你想無限放大數據,它很有用:
Sub ExpandChartSource()
Dim ObjChart As Object
Dim RngSource As Range
Dim IntSeries As Integer
Dim StrAddress As String
Set ObjChart = ActiveSheet.ChartObjects(1)
Set RngSource = Range(Split(ObjChart.Chart.SeriesCollection(1).Formula, ",")(2))
StrAddress = RngSource.Cells(1, 1).Address
Set RngSource = Range(Split(ObjChart.Chart.SeriesCollection(ObjChart.Chart.SeriesCollection.Count).Formula, ",")(2))
StrAddress = StrAddress & ":" & RngSource.Cells(RngSource.Rows.Count, 1).Address
Set RngSource = Range(StrAddress)
Set RngSource = RngSource.Resize(RngSource.Rows.Count, RngSource.Columns.Count + 1)
ObjChart.Chart.SetSourceData Source:=RngSource
End Sub
它假定第一個系列是最左邊的系列,而最后一個系列被假定為最右邊的系列。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.