简体   繁体   English

下标超出单元格引用的范围错误

[英]subscript out of range error on cell reference

I don't understand why this has an error : 我不明白为什么会有错误:

Dim h As String
h = Worksheets("beans").range("O11").Value.Offset(ref_count, 0)

ref_count is used in a loop, h is passed elsewhere in the program. ref_count在循环中使用, h传递到程序的其他位置。 I am getting a run time error 9 subscript out of range error and I don't understand why 我收到运行时错误9下标超出范围错误,我不明白为什么

please help me. 请帮我。

thanks. 谢谢。

So your current code is trying to offset a value. 因此,您当前的代码正在尝试抵消一个值。

This is not possible. 这是不可能的。

You need to offset the range and fetch the value from this new location. 您需要偏移范围并从此新位置获取值。 You were close but not quite there. 你很近但是还没到那儿。

The code should look like this: 该代码应如下所示:

Dim h As String
h = Worksheets("beans").range("o11").Offset(ref_count, 0).Value

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

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