简体   繁体   中英

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. I am getting a run time error 9 subscript out of range error and I don't understand why

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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