[英]run-time error '1004' on range selecting
我在此代码上收到运行时错误“ 1004”
sh2是另一个文件上的特定工作表。 我不想激活第二张纸,只需使用它然后关闭文件即可。 我在其他情况下得到我的错误
If sh2.Range(sh2.Cells(1, y + 4), sh2.Cells(1, y + 4)) <> "" Then
y = y + 1
Else: sh2.Range(sh2.Cells(1, 4), sh2.Cells(114, (y + 4) - 1)).Select
Selection.Copy
当我尝试调试时:y为49(必须如此),else下范围的单元格将获得自己正确的值。 我的错误在哪里?
PS。 我正在使用excel 2013并且在此代码之前y设置为0
尝试sh2.Range(sh2.Cells(1, 4), sh2.Cells(114, (y + 4) - 1)).Copy
(不选择)我认为除非激活它,否则您无法选择工作表上的任何内容
您的原始代码对我有用-如果删除Select
会发生什么?
Dim sh2 As worksheet
Set sh2 = Sheets(2)
y = 49
If sh2.Range(sh2.Cells(1, y + 4), sh2.Cells(1, y + 4)) <> "" Then
y = y + 1
Else
sh2.Range(sh2.Cells(1, 4), sh2.Cells(114, (y + 4) - 1)).Copy
End If
我认为如果您放弃sh2.
从sh2.range
内它将起作用。
将sh2.Range(sh2.Cells(1, y + 4), sh2.Cells(1, y + 4))
更改为
sh2.Range(Cells(1, y + 4), Cells(1, y + 4))
虽然未经测试
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.