简体   繁体   English

来自另一张工作表的Excel VBA范围副本

[英]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.

相关问题 excel vba 范围从一张纸复制到另一张纸(错误 1004) - excel vba range copy from one sheet to another (error 1004) 来自另一张纸的VBA复制范围 - VBA copy range from another sheet 在 excel VBA 中复制行范围从 Sheet1 到 Sheet2 - Copy rows range from Sheet1 to Sheet2 in excel VBA Excel VBA查看工作表并将列范围复制到另一个工作表 - Excel VBA look through sheets and copy column range to another sheet Excel Vba将列中的数据范围复制到另一个工作表 - Excel Vba to copy a range of data in columns to another sheet Excel VBA-将范围从一张纸复制到另一张纸,下一个空行 - Excel VBA - Copy range from one sheet to another, next empty row 试图将特定范围从工作簿中的许多工作表复制到另一个工作簿中的一个工作表 vba excel? - Trying to copy specific range from many sheets in workbook to one sheet in another workbook vba excel? Excel VBA将行范围从一个工作表复制到另一工作表的特定行 - Excel VBA to copy a row range from one sheet to a particular row in another Excel 2010 VBA - 运行时错误1004 - 使用匹配将范围从一个工作表复制到另一个工作表 - Excel 2010 VBA - runtime error 1004 - using match to copy range from one sheet to another Excel VBA-从工作表复制(扫描名称),然后将其插入另一工作表 - Excel VBA - Copy from a sheet (scan for name) then insert it in another sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM