我试图编写一个脚本来复制数据透视表并将值粘贴到另一个工作表中。出于某种原因,如果我不在az跟踪器表上启动脚本,脚本将复制(并填充)错误的范围。你能看出问题出在哪里吗?
Sub updateazdata()
Dim wbmodel As Excel.Workbook
Set wbmodel = Workbooks("AMS")
Dim col As Long
Dim lastcol As Long
Dim lastrow As Long
Dim rng As Range
Dim azurerng As Range
wbmodel.Sheets("Az order book").PivotTables("Azpivot").PivotSelect "", xlDataandlabels
Set rng = Selection.Offset(2, 0)
rng.Select
Set azrng = wbmodel.Sheets("az Tracker").Range("G4").Resize(rng.Rows.Count, rng.Columns.Count)
azrng.Value = rng.Value
Set azrng = azrng.SpecialCells(xlCellTypeBlanks)
azrng.Select
'azrng.FormulaR1C1 = "=R[-1]C"
End Sub
感谢您的帮助!