我想將數據添加到一堆現有圖表。假設每個圖表具有不同數量的數據序列,並且原始數據的位置在同一工作簿中的某處。這裏是我開始用:Excel VBA - 獲取圖表數據範圍
For iChart = 1 To iCount
ActiveSheet.ChartObjects("Chart " & iChart).Activate
intSeries = 1
Do Until ActiveChart.SeriesCollection(intSeries).Name = ""
Set rXVal = ActiveChart.SeriesCollection(intSeries).XValues '<- Object Required error
Set rXVal = Range(rXVal, rXVal.End(xlDown))
Set rYVal = ActiveChart.SeriesCollection(intSeries).Values
Set rYVal = Range(rYVal, rYVal.End(xlDown))
ActiveChart.SeriesCollection(intSeries).XValues = rXVal
ActiveChart.SeriesCollection(intSeries).Values = rYVal
intSeries = intSeries + 1
Loop
Next iChart
我知道ActiveChart...XValues = rXVal
的作品,但我對Set rXVal = ActiveChart....XValues
線得到「對象需要」錯誤。我假設,自從一個範圍進入定義數據系列後,我可以再次將該範圍返回並添加到該範圍。
UPDATE
爲了澄清事情的話,我有8個地方和FFT軟件安裝加速度計來記錄4個單獨的頻段峯值振動響應。這樣每個樣本產生32個數據點。在導出時,軟件會分出4張Excel工作簿;每個頻段一個。每張表都有加速度計名稱,樣本數量也在減少。
'Values'和'XValues'(儘管您可以將它們設置爲一個範圍,*返回*一個變體數組)請嘗試尋求幫助http://j-walk.com/ss/excel/tips/tip83.htm – 2015-02-05 23:57:45
您可以嘗試聲明一個Series類型的變量,然後從諸如.ForumlaR1C1之類的屬性中解析出範圍地址。例如:Dim s As Series: Set s = ActiveChart.SeriesCollection(1): Debug.Print s.FormulaR1C1 – Mike 2015-02-06 04:56:16