1

I've run into a problem, I cannot seem to figure out, using basic array functionalities. I'm using the following (standard) code:

Sub CC()

Dim arrB As Variant
arrB = Sheet2.Range("B3:B100").Value2

Debug.Print LBound(arrB) & " " & UBound(arrB)
Debug.Print arrB(LBound(arrB))

End Sub

The first Debug.Print statement returns "1 98" as expected. But when I try to access any values inside the array arrB with my second Debug.Print I'm getting a run-time error 9 (Index out of range). Any ideas on what I'm missing here?

2
  • 2
    Try Debug.Print arrB(LBound(arrB),1) Commented Oct 4, 2019 at 9:01
  • 1
    That was quick, thank you! Somehow I didn't think of the array's second dimension since I'm only putting one column of values into it. Feel free to post it as an answer, so the question can be closed. :) Commented Oct 4, 2019 at 9:03

1 Answer 1

2

Try:

Debug.Print arrB(LBound(arrB),1)

For future tasks with arrays - that was quick because I had many many struggles before, the easiest way to deal with arrays is to Add Watch on them.

By that You would see how it looks and how many dimensions it has :)

I'm glad that I could help :)

Sign up to request clarification or add additional context in comments.

1 Comment

Described problem on simpleexcelvba.com/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.