Vba 从其他工作表中选择范围时出错
我想选择Excel工作簿第一页上的区域,无论它是否处于活动状态Vba 从其他工作表中选择范围时出错,vba,excel,Vba,Excel,我想选择Excel工作簿第一页上的区域,无论它是否处于活动状态 Set WorkRng = Sheets(1).Range(Cells(9, 4), Cells(39, colNum)) 这将返回错误: Run-time error: 1004 Application-defined or object-defined error 仅当未选择第一张图纸时 注:colNum=11 如何修复此错误?您的方法是正确的,因为您使用的是显式图纸对象(这很好)。分解的地方是如何指定范围对象 你的密码是
Set WorkRng = Sheets(1).Range(Cells(9, 4), Cells(39, colNum))
这将返回错误:
Run-time error: 1004
Application-defined or object-defined error
仅当未选择第一张图纸时
注:colNum=11
如何修复此错误?您的方法是正确的,因为您使用的是显式图纸对象(这很好)。分解的地方是如何指定范围对象 你的密码是
Set WorkRng = Sheets(1) <-- use sheet "1" as the reference for generating the range
.Range(
Cells(9, 4) <-- compose the range starting with cells R9C4 in the *Activesheet*
, Cells(39, colNum) <-- end the range composure with cells R29C[colnum] in the *Activesheet*
)
或者
With Sheets(1)
Set WorkRng = .Range(.Cells(9, 4), .Cells(39, colNum))
End With
注意
范围
和单元格
之前的
。这意味着它们都来自同一张纸。否则就不合逻辑。谢谢,我得到错误:1004-Range类的Select方法失败
With Sheets(1)
Set WorkRng = .Range(.Cells(9, 4), .Cells(39, colNum))
End With