Consulting

Results 1 to 5 of 5

Thread: Solved: Loading a range into a matrix

  1. #1
    VBAX Regular
    Joined
    Jan 2006
    Posts
    30
    Location

    Solved: Loading a range into a matrix

    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:

    [vba]
    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
    [/vba]

    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..

    I am obviously missing something... but what?


    Thymen

  2. #2
    VBAX Contributor
    Joined
    Jul 2005
    Posts
    169
    Location
    Hi
    what do you want to do with this line?

    MsgBox myMatrix(5)

  3. #3
    VBAX Regular
    Joined
    Jan 2006
    Posts
    30
    Location
    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

  4. #4
    VBAX Contributor
    Joined
    Jul 2005
    Posts
    169
    Location
    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..

  5. #5
    VBAX Regular
    Joined
    Jan 2006
    Posts
    30
    Location
    Thanks, I'll tried that and it works....

    Thymen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •