2017-09-25 130 views
0
SetSourceData

所以我看到這個:https://msdn.microsoft.com/VBA/PowerPoint-VBA/articles/chart-setsourcedata-method-powerpoint,我已經使用了類似的東西:如何正確地在PowerPoint中使用

.Chart.SetSourceData _ 
    Source:="='Sheet1'!$A$1:$D$5", _ 
    PlotBy:=xlColumns 

這一切工作正常和良好。但是現在我該如何開始使用變量來定義我需要的範圍呢? .Cells在這裏似乎不起作用,我想要做的是找到使用的第一行和最後一行/列,並放在範圍內。我只知道如何使用.Cells來做到這一點。似乎我錯過了一些東西......有沒有這樣做的好方法我沒有看到?

我真的不明白Source=之後的格式是如何工作的。

在此先感謝

+1

您可以使用'Range.Address'並在'Source ='中使用它,類似於使用帶有變量的工作表公式:'Source =「=」&Range.Address&「」' –

+0

@VictorK說我有東西看起來像這樣:'Dim LastRow As Long Dim LastColumn As Long LastRow =工作表(1).UsedRange.Rows.Count LastColumn =工作表(1).UsedRange.Columns.Count'我如何使用Address來更改'Source:=「='Sheet1'!$ A $ 1:$ D $ 5」'上面? – Pinlop

+1

未測試,但我會嘗試:'Source:=「=」'Sheet1'!「&.Range(.Cells(1,1),. Cells(LastRow,LastColumn))。Address&」「'。 '.Range'和'.Cells'應該以某種方式完全符合工作表的要求。 –

回答

1
Source:= "='Sheet1'!" & _ 
.Range(.Cells(1,1),.Cells(LastRow,LastColumn)).Address & _ 
"" 

注意兩個.Range.Cells應該以某種方式工作表完全quallified。