VBA Excel:复制带有起始位置和目标位置的列

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

VBA Excel: Copy column with start position and destination position

excelvbacopyrange

提问by tmighty

I would like to copy the values of a column from one worksheet to another worksheet that already has rows.

我想将一列的值从一个工作表复制到另一个已经有行的工作表。

I want to add the values in column A in worksheet "source" to column X in worksheet "dest". But I want to skip the first 2 rows of the source column, and the values should be inserted after the 2000th row.

我想将工作表“源”中的 A 列中的值添加到工作表“dest”中的 X 列中。但我想跳过源列的前 2 行,值应该插入到第 2000 行之后。

For example like this:

例如像这样:

Workbook.Sheets("source").Columns("A3:A").Copy Destination:=nDestSheet.Range("X2001")

But VBA is telling me about a Type Mismatch. I guess I am just doing something wrong in regards to the syntax.

但是 VBA 告诉我类型不匹配。我想我只是在语法方面做错了。

Can somebody help please?

有人可以帮忙吗?

Thank you!

谢谢!

回答by GSerg

.Columnsaccepts column number or letter, not a range. That's not exactly important as "A3:A" is not a valid range anyway.

.Columns接受列号或字母,而不是范围。这并不重要,因为无论如何“A3:A”都不是有效范围。

You probably want

你可能想要

With Workbook.Sheets("source")
  .Range(.Range("A3"), .Columns("A").Cells(.UsedRange.Rows(.UsedRange.Rows.Count).Row)).Copy Destination:=nDestSheet.Range("X2001")
End With

回答by Simone Longoni

How about a simple:

一个简单的怎么样:

Workbook.Sheets("source").Columns("A").Copy Destination:=nDestSheet.Range("X2001")