excel vba - 如何将数据透视表中的所有字段复制到同一工作表中的其他单元格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14085172/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 19:00:18  来源:igfitidea点击:

excel vba - how to copy all the fields in a pivot table to other cells in the same sheet

excelvbapivot-table

提问by user1040563

I have a user form in excel with a combo box and when I choose something in the combobox it automatically updates a pivot table in a certain sheet. now I want to take all the fields that are now in the pivot table and copy them to another coulmn. I need to write it in vb but for some reason it wont copy the cells. that is my code:

我有一个带有组合框的 excel 用户表单,当我在组合框中选择某些内容时,它会自动更新某个工作表中的数据透视表。现在我想获取现在在数据透视表中的所有字段并将它们复制到另一个库姆。我需要用 vb 编写它,但由于某种原因它不会复制单元格。那是我的代码:

Set x = ActiveSheet.PivotTables("PivotTable4.1").DataBodyRange.Cells
x.Copy
Application.Goto Reference:="pivot_paste"
x.Paste

everthing works fine except the last line for some reason please help

除了最后一行出于某种原因,一切正常,请帮忙

回答by Doug Glancy

x.Pastemeans to copy it to the range x, which is clearly not what you want. Something like this should work:

x.Paste意味着将其复制到范围x,这显然不是您想要的。这样的事情应该工作:

Set x = ActiveSheet.PivotTables("PivotTable4.1").DataBodyRange.Cells
x.Copy Destination:=ActiveSheet.Range("pivot_paste")