简体   繁体   English

Sheets(“sheet_1”).ActiveCell.Offset(0, i + 1).Range(“A1”).Value 的正确语法是什么

[英]What is the correct syntax for Sheets(“sheet_1”).ActiveCell.Offset(0, i + 1).Range(“A1”).Value

What is the correct syntax for telling VBA告诉 VBA 的正确语法是什么

"consider the value in sheet_1 in the cell that has offset (0,i) from the activecell"? “考虑与活动单元格有偏移(0,i)的单元格中 sheet_1 中的值”?

I tried with我试过了

Sheets("sheet_1").ActiveCell.Offset(0, i).Range("A1").Value

but it gives me但它给了我

runtime error 438运行时错误 438

Please note that my aim is to do:请注意,我的目标是:

If Sheets("sheet_1").ActiveCell.Offset(0, i).Range("A1").Value = Sheets("sheet_23").ActiveCell.Offset(0, i).Range("A1").Value Then

'do something

The ActiveCell is only the single active cell in whichever sheet is active at the time the code is run. ActiveCell只是在代码运行时处于活动状态的任何工作表中的单个活动单元格。 It cannot refer to a cell on an inactive sheet.它不能引用非活动工作表上的单元格。 Another sheet must be activated first.必须先激活另一个工作表。

Of course you can use the Address property of an activecell and refer to the corresponding cell on an inactive sheet.当然,您可以使用活动单元格的Address属性并引用非活动工作表上的相应单元格。

In general, it is recommended not to use activecell or selection .一般来说, 建议不要使用 activecell 或 selection

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

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