通过宏在数据透视表中插入数据

时间:2015-09-29 16:41:19

标签: excel excel-vba pivot-table vba

目的是在页面INPUT上动态复制完整范围的数据到第Table16页的数据透视表OUTPUT - 在标题NAME下的第一个单元格中

数据透视表中的一个小注释(某种模板)包含更多列,然后只包含我要复制的3列。

Sub SelectCopy()
 '
 ' SelectCopy Macro
 '

' the intention is to copy dynamically  the complete range of data - on page INPUT
 ' to the pivot table Table16 on OUTPUT page - in the first cel under the title NAME

Range_cels = Sheets("info").Range("M4").Value

    ThisWorkbook.Sheets("input").Select

     Range(Range_cels).Select
     Selection.Copy

      MsgBox "The data has been successfully copied."

     ThisWorkbook.Sheets("output").Select
     '1/
     'table16 is a pivot table, wanted select the first cell beneath the title row
     ' complains about 'ActiveSheet.Paste' failure
     ActiveCell.Offset(0, 0).Range("Table16[[#Headers],[Name]]").Select
     '2/ - works fine but puts it in the last selected cell
     'ActiveCell.Offset(rowOffset:=0, columnOffset:=0).Activate
     '3/ - fails complains it is in pivot table
     'Range("A2").Select

      MsgBox "almost ... pasted."

     ActiveSheet.Paste

      MsgBox "The data has been successfully pasted."
      MsgBox "The data has been successfully copied & pasted."

End Sub

enter image description here

方法1:

ActiveCell.Offset(0, 0).Range("Table16[[#Headers],[Name]]").Select 

给出错误1004:

enter image description here

这是数据透视表:

enter image description here

0 个答案:

没有答案