目的是在页面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
方法1:
ActiveCell.Offset(0, 0).Range("Table16[[#Headers],[Name]]").Select
给出错误1004:
这是数据透视表: