vba 复制数据透视表格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10418875/
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
Copying Pivot Table Formats
提问by Billy
I'm having trouble getting pivot table formats to copy to a new sheet. Basically what I'm trying to do is this:
我无法将数据透视表格式复制到新工作表。基本上我想做的是这样的:
someRange.Copy
someOtherRange.pasteSpecial xlPasteValues
someOtherRange.pasteSpecial xlPasteFormats
Basically, I want an exact copy of the current view on a pivot table in a new sheet but I just want the values and formatting (and not be connected to the pivot table any longer). Doing this procedure by hand produces the correct result, but for some reason the formatting doesn't copy when I use the same approach via vba... Thoughts?
基本上,我想要一个新工作表中数据透视表上当前视图的精确副本,但我只想要值和格式(不再连接到数据透视表)。手动执行此过程会产生正确的结果,但由于某种原因,当我通过 vba 使用相同的方法时,格式不会复制......想法?
Update:Exact code as requested:
更新:按要求提供的确切代码:
Application.CutCopyMode = False
pivotSheet.Range(pivotSheet.usedRange.Cells(1, 2), pivotSheet.Cells(pivotSheet.usedRange.Rows.Count, pivotSheet.Columns.Count)).Copy
updatesSheet.Range(updatesSheet.Cells(1, 1), updatesSheet.Cells(pivotSheet.usedRange.Rows.Count, pivotSheet.usedRange.Columns.Count)).PasteSpecial xlPasteValues
updatesSheet.Range(updatesSheet.Cells(1, 1), updatesSheet.Cells(pivotSheet.usedRange.Rows.Count, pivotSheet.usedRange.Columns.Count)).PasteSpecial xlPasteFormats
Application.CutCopyMode = False
采纳答案by Siddharth Rout
TRIED AND TESTED
久经考验
Option Explicit
Sub Sample()
With Sheets("Sheet1")
.Range("H1:I6").Copy
With .Range("M7")
.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
End With
End With
End Sub
SNAPSHOT
快照
回答by Jon Crowell
Before copying and pasting manually, start recording a macro. After you're finished, stop the recording and examine the recorded code. You'll get a bunch of extra stuff you can delete, but you'll also get the correct syntax for doing what you're trying to do.
在手动复制和粘贴之前,开始录制宏。完成后,停止录制并检查录制的代码。你会得到一堆可以删除的额外内容,但你也会得到正确的语法来做你想做的事情。