vba VBA简单地将一个范围复制到另一个范围

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7504543/
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-08 11:55:08  来源:igfitidea点击:

VBA Simple Copying one Range to Another Range

vbaexcel-2011

提问by SparrwHawk

This is a really simple VBA formula but it's failing. It's only pasting into cell A6 onwards. Is it just me? Excel 2011 by the way.

这是一个非常简单的 VBA 公式,但它失败了。它只是粘贴到单元格 A6 以后。只有我吗?顺便说一下,Excel 2011。

Range("A4:A5").Select
Selection.Copy
Range("A6:A1000").Select
ActiveSheet.Paste

回答by Alex P

I think the issue is that you have two different values in A4 and A5 and so excel can only repeat those values in the paste range if the paste range is an even number of cells.

我认为问题在于您在 A4 和 A5 中有两个不同的值,因此如果粘贴范围是偶数个单元格,excel 只能在粘贴范围内重复这些值。

This works for me:

这对我有用:

Range("A4:A5").Copy Destination:=Range("A6:A1001")

Note that A6:1001 is 996 cells (an even number). Using A6:A1000 is 995 and is an odd number so excel cannot work out how to repeat your values from A4 to A5.

请注意,A6:1001 是 996 个单元格(偶数)。使用 A6:A1000 是 995 并且是一个奇数,因此 excel 无法计算出如何从 A4 到 A5 重复您的值。

I think this is the issue...but happy to be educated otherwise...

我认为这就是问题所在……但很高兴接受其他教育……