VBA:将命名范围粘贴为值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22210675/
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
VBA: Paste named range as value
提问by MathLover
I have a dynamic named range, call it "MYRange" in worksheet "Data1". By dynamic I mean that the range is coded as
我有一个动态命名范围,在工作表“Data1”中将其称为“MYRange”。动态我的意思是范围被编码为
=offset(A1,0,0, COUNTA(A:A),1).
The actual values that populate these cells are done via a vlookup. I want to copy this range into another workbook called "Data2" as values, otherwise I get a reference issue.
填充这些单元格的实际值是通过 vlookup 完成的。我想将此范围作为值复制到另一个名为“Data2”的工作簿中,否则我会遇到一个参考问题。
Thanks!
谢谢!
回答by ja72
To copy values between two ranges use:
要在两个范围之间复制值,请使用:
Range("MyDestRange").Value = Range("MySrcRange").Value
Make sure the two ranges are the same shape and number of cells. You can manipulated those with the .Resize()
and .Offset()
methods to get what you need.
确保两个范围具有相同的形状和单元格数量。您可以使用.Resize()
和.Offset()
方法操纵它们以获得您需要的东西。
回答by David Zemens
Assuming your named range has a name like "MyRange", something like this:
假设您的命名范围具有类似“MyRange”的名称,如下所示:
Dim srcRange as Range, destRange as Range
Set srcRange = Range("MyRange")
Set destRange = Workbooks("Data2").Worksheets(1).Range("A1").Resize(srcRange.Rows.Count, srcRange.Columns.Count)
destRange.Value = srcRange.Value
回答by Paul Lear
Range("Named_Range_Name_Here").copy
Range("Sheet_Name").Range("Cell Reference").PasteSpecial Paste:=xlPasteValues
Pasting to a single cell will paste data just as you would. It will start the paste from there and pastes the names range down, unless you choose to Transpose it.
粘贴到单个单元格将像您一样粘贴数据。它将从那里开始粘贴并将名称范围向下粘贴,除非您选择转置它。