我想弄清楚如何使用VBA更改數據更改我的數據透視表源數據到行的末尾。我當前的代碼如下:VBA更新數據透視表的源數據到行尾
Dim shBrandPivot As Worksheet
Dim shCurrentWeek As Worksheet
Dim shPriorWeek As Worksheet
Dim shPivot As Worksheet
Dim lr As Long
Set shBrandPivot = ActiveWorkbook.Sheets("Brand Pivot")
Set shCurrentWeek = ActiveWorkbook.Sheets("Current Week")
Set shPriorWeek = ActiveWorkbook.Sheets("Prior Week")
Set shPivot = ActiveWorkbook.Sheets("Pivot")
lr = shCurrentWeek.Range("A" & Rows.Count).End(xlUp).Row
With ActiveWorkbook.Sheets("Pivot").Activate
ActiveSheet.PivotTableWizard SourceType:=xlDatabase, SourceData:="CurrentWeek!A3:X & lr"
End With
我正的錯誤是運行時錯誤1004:無法打開數據透視表源文件:E:\脫機\ KXM2103 \ DATA \ CurrentWeek
是否可以使用動態定義的範圍,然後在代碼中簡單地刷新數據透視表?你的數據如何更新? – scott
@scott現在,我的數據正在手動更新,轉到選項 - >更改源數據。我正在考慮嘗試你所討論的方法,但我想看看是否有辦法通過VBA專門做到這一點。 – kmiao91