Named range into an array

F

Frigster

Hi,

I have five cells on a row (A1:A5). This range is named "xyz".
How can I transform this range in an array with VB code?

Thank you.
Paolo.
 
G

Gary''s Student

Try:

Sub gsnu()
Dim r As Range
Dim v(10)
i = 1
For Each r In Range("xyz")
v(i) = r.Value
i = i + 1
If i = 6 Then Exit For
Next

End Sub

as coded it picks up the first 5 values in "xyz" and does not examine
Range("xyz").Count to get the full range.


Note that Range("xyz") is the equivalent of Range("A1:A5"). A Name is just
a string.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top