用于复制数据透视表数据并填充字段的VBA代码

时间:2017-04-20 20:54:46

标签: excel vba excel-vba

我试图编写一个脚本来复制数据透视表并将值粘贴到另一个工作表中。出于某种原因,如果我不在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

感谢您的帮助!

0 个答案:

没有答案