【发布时间】:2021-03-18 19:24:39
【问题描述】:
已经创建了一个数据透视表,我需要一个宏,它可以从指定的工作表 (Pivot1) 中提取没有过滤器的数据透视主体数据,并将结果复制到下一个空白单元格上的另一个工作表 (Selection) 中。
我已经使用并修改了以下内容,我在这个网站上找到了它,但是它没有拿起我的床单,我得到一个运行时错误“424” 有关如何执行此操作的任何想法?
Sub PastePivot()
Dim i As Long
Dim LR As Long
Dim j As Long
Dim c As Long
'Find last used row in Pivot1
LR = Pivot1.Cells(Pivot1.Rows.Count, 1).End(xlUp).Row
'Find last used row in Selection
j = Selection.Cells(Selection.Rows.Count, 1).End(xlUp).Row
'Loop through rows on Pivot1
For i = 3 To LR
'Decide whether to copy the row or not
If Pivot1.Cells(i, 1).Value <> "0" Then
'Update pointer to the next unused row in Selection
j = j + 1
'Only copy used columns, to stop it thinking every cell in the
'destination row is "used"
c = Pivot1.Cells(i, Pivot1.Columns.Count).End(xlToLeft).Column
'Copy the values (without using Copy/Paste via the clipboard)
Selection.Rows(j).Resize(1, c).Value = Pivot1.Rows(i).Resize(1, c).Value
End If
Next i
结束子
【问题讨论】:
标签: excel vba pivot-table