vba 将 Excel 工作表复制到另一本 Excel 书籍,但仅复制格式和值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14881032/
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
Copy Excel sheet to another excel book but just formats and values
提问by Jonathan Raul Tapia Lopez
I have two excel workbooks Book_Aand Book_Band I know how to copy an entire sheet from A -> Bwith:
我有两个 Excel 工作簿Book_A和Book_B,我知道如何从A -> B复制整个工作表:
wksSh1.Copy Before:=wkbBook_B.Sheets(1)
But I just want to copy the sheet with values and formats and not formulas. It is posible
但我只想复制带有值和格式而不是公式的工作表。这是可能的
回答by Tim Williams
wksSh1.Copy Before:=wkbBook_B.Sheets(1)
with wkbBook_B.Sheets(1).UsedRange
.value = .value 'converts formulas to values
end with
回答by Francis P
Use PasteSpecial
:
使用PasteSpecial
:
wksSh1.Copy
With wkbBook_B.Sheets(1)
.PasteSpecial xlPasteFormats
.PasteSpecial xlPasteValues
End With
As Scott commented, for earlier versions of Excel (2003 +), you can use xlPasteValuesAndNumberFormats
.
正如 Scott 评论的那样,对于早期版本的 Excel(2003 +),您可以使用xlPasteValuesAndNumberFormats
.
回答by Federico Cattozzi
If you know the number of rows and columns (or you can use a row and a column always valued to calculate them) this is safer:
如果您知道行数和列数(或者您可以使用始终有价值的行和列来计算它们),则更安全:
For i = 2 To numberOfRows
For j = 1 To numberOfColumns
Cells(i, j).Value = Cells(i, j).Value
Next
Next