VBA粘贴范围与动态选择(VBA paste range with dynamic selection)

编程入门 行业动态 更新时间:2024-10-11 17:19:28
VBA粘贴范围与动态选择(VBA paste range with dynamic selection)

我阅读了多个Q&A,但是我很难真正理解使用不同对象的所有长文字。

我试图从一个工作表中选择一个范围到另一个工作表。 我想保持范围动态,因为范围可以每次都有所不同。 通过这样做,我使用了以下脚本:

Dim range As Long For range = ActiveCell To ActiveCell.End(xlDown) Sheets("Stock Report").range("A4" & range).Value = Sheets("Unique File").range("Y8" & range).Value

但它什么都不做。

这个脚本可以工作,但我想保持最后一个单元格的动态:

Sheets("Stock Report").Range("A4:A9000").Value = Sheets("Unique File").Range("Y8:Y90004").Value

我必须对多个列进行此操作,这些列是通过使用不同工作表中的其他文件计算出来的,并且最终需要对它们进行排序,而不必在另一个列表中进行所有计算。

有什么建议么?

I read multiple Q&A's, however it's difficult for me to really understand all the long scripts with the usage of different objects.

I am trying to select a range from one worksheet to an other. I want to keep the range dynamic, because the range can vary every time. By doing so I have used the following script:

Dim range As Long For range = ActiveCell To ActiveCell.End(xlDown) Sheets("Stock Report").range("A4" & range).Value = Sheets("Unique File").range("Y8" & range).Value

However it doesn't do anything.

This script does work, but I would like to keep the last cell dynamic:

Sheets("Stock Report").Range("A4:A9000").Value = Sheets("Unique File").Range("Y8:Y90004").Value

I have to do this for multiple columns which are calculated by using other files in a different worksheets and need to sort them finally without all the calculations in an other one.

Any suggestions?

最满意答案

好的,试试。

Sheets("Unique File").Range("Y8:Y" & Sheets("Unique File").Range("A4").End(xlDown).Row + 4).Copy Sheets("Stock Report").Range("A4").PasteSpecial Paste:=xlPasteValues

范围(“A4”)。结束(xlDown).Row获取库存报表工作表上数据的最后一行,并用于复制到唯一文件表单中的同一行。 我添加了4,因为您的范围从唯一文件工作表上的8开始。

我认为你的代码不起作用,因为你试图使用从“唯一值”工作表上的“库存报表”中创建的“范围”。

OK try.

Sheets("Unique File").Range("Y8:Y" & Sheets("Unique File").Range("A4").End(xlDown).Row + 4).Copy Sheets("Stock Report").Range("A4").PasteSpecial Paste:=xlPasteValues

Range("A4").End(xlDown).Row gets the last row of the data on the Stock Report sheet and is used to copy down to the same row on the Unique File sheet. I added 4 because your range starts on 8 on the Unique File sheet.

I think your code didn't work because you were trying to use the "range" you created from the Stock Report sheet on the Unique values sheet.

更多推荐

本文发布于:2023-08-07 00:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1459123.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:动态   paste   VBA   selection   dynamic

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!