PDA

View Full Version : Solved: Loading a range into a matrix



Thymen
05-02-2006, 01:30 AM
Hi folks;

anyone able to tell me how I can load a (named) range into a matrix, without loading each element one at a time? If I run someting like:


Option Explicit
Option Base 1
Private myMatrix As Variant
Private Sub UserForm_Initialize()
myMatrix = Range("TestRange")
MsgBox UBound(myMatrix)
MsgBox LBound(myMatrix)
MsgBox myMatrix(5)
End Sub


with TestRange a named range, it shows correct UBound, but I get a 'Subscript out of range" when I want to show a matrix value..:banghead:

I am obviously missing something... but what?:dunno


Thymen

jindon
05-02-2006, 02:03 AM
Hi
what do you want to do with this line?

MsgBox myMatrix(5)

Thymen
05-02-2006, 02:37 AM
Show the value of myMatrix item 5. The named range is 1 column wide / 10 rows deep. So, with msgbox myMatrix(5) I should get a message showing the value ot the 5th row....

Just to indicate that the matrix got filled with data.

Thymen

jindon
05-02-2006, 02:39 AM
then

msgbox myMatrix(5,1)

sorry, but I must go off-line now,

Remenber when you convert range value to an array
the array is always 2D array, regardless of the number of row/column..

Thymen
05-03-2006, 11:23 PM
Thanks, I'll tried that and it works....

Thymen