[英]Excel VBA range copy from another sheet
I have a line of code that I am having issues troubleshooting. 我有一行代码在解决问题时遇到问题。
Sheets("data").Range(cells(2,1), cells(2, column).Copy
I'm getting a 1004 application or object defined error
on this. 我在此上收到
1004 application or object defined error
。 The code works if I remove the worksheet selection or replace the range chunk with a hardcoded reference (e4:e50 for example), but won't work together. 如果删除工作表选择或将范围块替换为硬编码的引用(例如e4:e50),该代码将起作用,但无法一起使用。
Right now you have the Range looking at one sheet and the Cells are looking at the active sheet. 现在,您可以看到Range在一张纸上,而Cell在看活动纸。 You need to make sure they are looking at the same sheet.
您需要确保他们正在看同一张纸。
You can do this in line: 您可以按照以下步骤进行操作:
Sheets ("data").Range(Sheets ("data").cells (2,1), Sheets ("data").cells (2, column)). Copy
Or you can use a With Block for less typing 或者,您可以使用带阻止功能来减少打字
With Sheets ("data")
.Range(Sheets (.cells (2,1), .cells (2, column)). Copy
End With
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.