vba 将数据复制到特定列的最后使用的行

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

Copy data upto last used Row of a specific column

excel-vbavbscriptvbaexcel

提问by Praveenks

I am using this code to get the last used rows-

我正在使用此代码获取最后使用的行-

rowNo=objExcel.Activeworkbook.Sheets(1).UsedRange.Rows.count

rowNo=objExcel.Activeworkbook.Sheets(1).UsedRange.Rows.count

Now, i want to copy the data of a specific column upto last row used.

现在,我想将特定列的数据复制到使用的最后一行。

//What to write in the below code to use rowNo //

//在下面的代码中写什么来使用rowNo //

Set Source=objExcel.Activeworkbook.Sheets(1).Column("G")

Set Source=objExcel.Activeworkbook.Sheets(1).Column("G")

Source.Copy

Source.Copy

回答by Siddharth Rout

That's the incorrect way to find the last row. See the linkon how to find the last row.

这是查找最后一行的错误方法。请参阅有关如何查找最后一行的链接

Once you have found the last row then simply use this code to copy

找到最后一行后,只需使用此代码即可复制

ws.Range("G1:G" & rowNo).Copy

Where wsis the worksheet object.

ws工作表对象在哪里。