0

I have values stored in a sheet called config, and goes from H2 (the list is dynamic as more can be added) So I am using the following code:

roomCount = ActiveWorkbook.Worksheets("config").Range("H2", Worksheets("config").Range("H2").End(xlDown)).Rows.Count

So, this gives me the number of rows.

What I am trying to do, but I just can't see to get my head around is, do a loop to store these values from H2 onwards (using my code above) into an array.

and maybe for argument's sake msgbox the array upon a button click.

1 Answer 1

1

There is no need to loop through the cells to build an array. You can store the values directly in an Array like this:

Dim myvar as Variant    

myvar = ActiveWorkbook.Worksheets("config").Range("H2", Worksheets("config").Range("H2").End(xlDown))

And you can loop through all the elements using:

For Each ele In myvar
    Debug.Print ele
Next

Or directly access each individual element:

Debug.Print myvar(1,1) 'first element of the array
Debug.Print myvar(2,1) 'second element of the array
Sign up to request clarification or add additional context in comments.

1 Comment

This worked perfectly, thanks - I wasnt sure how to do this

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.