简体   繁体   English

在VBA中使用activecell和offset

[英]using activecell and offset in VBA

I am trying to test offset property in excel vba . 我正在尝试在excel vba中测试offset属性。 I am using a simple code which selects the cell which is daigonal , ie 1 row and 1 column away from the active cell. 我正在使用一个简单的代码,它选择的单元格是daigonal,即距活动单元格1行1列。

This is what I am doing 这就是我在做什么

Sub Range_Offset()

Range(ActiveCell).Offset(1, 1).Select

End Sub

I have attached the code to a button on the sheet. 我已将代码附加到工作表上的按钮上。

When I am clicking the button , I am getting the following error 当我单击按钮时,出现以下错误

Run-time error '1004'
Method 'Range' of object '_Global' failed

If i replacing the ActiveCell with any cell number its working . 如果我用任何单元号替换ActiveCell,它的工作原理。 But why is ActiveCell not working. 但是为什么ActiveCell不起作用。 Thanks 谢谢

Try: ActiveCell.Offset(1,1).select 尝试: ActiveCell.Offset(1,1).select
ActiveCell is already a range object, and you don't need to use Range() to turn it into range. ActiveCell已经是一个范围对象,您无需使用Range()将其转换为范围。

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

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