ActiveSheet.copy 问题(vba,excel)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5934822/
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
ActiveSheet.copy question (vba, excel)
提问by Gil Peretz
Hey guys, I have a small problem. I have a sheet called "main" that takes values from another files sheet called "data". When I active the "ActiveSheet.copy" (in the "main" file) it copies the sheet but with the cells links. I want to know if there is any way to copy just the values of the sheet?
嘿伙计们,我有一个小问题。我有一个名为“main”的工作表,它从另一个名为“data”的文件工作表中获取值。当我激活“ActiveSheet.copy”(在“主”文件中)时,它会复制工作表但带有单元格链接。我想知道是否有任何方法可以仅复制工作表的值?
Second, my "main" sheet has some merged cells so even if i manually copy & paste the sheets by selecting a range it can't be copied due to the merged cells.
其次,我的“主”工作表有一些合并的单元格,因此即使我通过选择范围手动复制和粘贴工作表,由于合并的单元格,它也无法复制。
P.S. I hope I explained myself well - as you can see English is not my first language.
PS 我希望我能很好地解释自己 - 正如你所看到的,英语不是我的第一语言。
Thank you
谢谢
回答by Alex P
Check out the options you get with PasteSpecial
:
查看您获得的选项PasteSpecial
:
- Values: this will not copy links and just values only
- All except borders: this will retain merged cell formatting
- 值:这不会复制链接,仅复制值
- 除边框外的所有:这将保留合并的单元格格式
Example - suppose you want to copy sheet1 to sheet 2 where sheet 1 has merged cells
示例 - 假设您要将 sheet1 复制到工作表 2,其中工作表 1 已合并单元格
- In Sheet1 press
CTRL + A
to select all and thenCTRL + C
to copy - In Sheet2 select cell A1
- Now right click and select
Paste Special...
- In the dialog box select
All except borders...
- 在 Sheet1 中按
CTRL + A
全选然后CTRL + C
复制 - 在 Sheet2 中选择单元格 A1
- 现在右键单击并选择
Paste Special...
- 在对话框中选择
All except borders...
Updated - VBA
更新 - VBA
Sub CopyWithMergedCells()
ActiveSheet.Cells.Copy //select all cells on sheet1 and copy
Worksheets("Sheet2").Select
Cells.Select //select all cells on sheet2
Selection.PasteSpecial Paste:=xlPasteAllExceptBorders, Operation:=xlNone, SkipBlanks:=False, Transpose:=False //paste with formats preserved
End Sub
Paste:=xlPasteAllExceptBorders
is the key bit. You need to change this if you want to just copy values (and not links)
Paste:=xlPasteAllExceptBorders
是关键位。如果您只想复制值(而不是链接),则需要更改此设置