简体   繁体   English

ActiveSheet.Range(Cells(x,y),Cells(w,z))。选择不起作用

[英]ActiveSheet.Range(Cells(x,y), Cells(w, z)).Select not working

Could anyone tell me why when I refer to a particular range it works fine: 谁能告诉我为什么当我提到一个特定范围时它可以正常工作:

ActiveSheet.Range("A1:D3").Select

but

ActiveSheet.Range(Cells(1, 1), Cells(3, 4)).Select

not working? 不工作吗?

I suspect your code is in the worksheet code module of a different sheet, so the unqualified Cells calls refer to that sheet, not the active one. 我怀疑您的代码在另一张工作表的工作表代码模块中,因此不合格的Cells格调用是指该工作表,而不是活动工作表。 You should always qualify all Range or Cells calls with a Worksheet object: 您应该始终使用Worksheet对象限定所有 RangeCells格调用:

ActiveSheet.Range(ActiveSheet.Cells(1, 1), ActiveSheet.Cells(3, 4)).Select

This also works avoiding the need to repeat several times the target worksheet: (see https://msdn.microsoft.com/EN-US/library/office/gg264723.aspx ) 这也可以避免重复几次目标工作表的需要:(请参阅https://msdn.microsoft.com/EN-US/library/office/gg264723.aspx

With ActiveSheet
    .Range(.Cells(1, 1), .Cells(3, 4)).Select
End With

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM