Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default Populate a matrix, How?

Hi,
I'm trying to populate a matrix but I can't figure it out a better way.

Example matrix:

[ 10 100 ]
[ 20 200 ]
[ 30 300 ]

I want a similar way to this: (that does not work)

Dim myMatrix As Variant
ReDim myMatrix(1 To 3, 1 To 2)
myMatrix = Array(Array(10, 20, 30), Array(100,200,300))

This redimensions the matrix to a 6 element array, so is not working as
I want it.
I know I can use "myMatrix(1,1) = 10" and so on, but I think there must
be a better way.
I also know that I can use a hidden sheet and then just copy the data
from the sheet to the matrix, but i'd like a only VBA code solution.

Can something like this be done?
Regards,
--
Beto
Reply: Erase between the dot (inclusive) and the @.
Responder: Borra la frase obvia y el punto previo.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Populate a matrix, How?

Dim myMatrix As Variant
myMatrix = Array(Array(10, 100), Array(20, 200), Array(30, 300))

Alan Beban

Beto wrote:
Hi,
I'm trying to populate a matrix but I can't figure it out a better way.

Example matrix:

[ 10 100 ]
[ 20 200 ]
[ 30 300 ]

I want a similar way to this: (that does not work)

Dim myMatrix As Variant
ReDim myMatrix(1 To 3, 1 To 2)
myMatrix = Array(Array(10, 20, 30), Array(100,200,300))

This redimensions the matrix to a 6 element array, so is not working as
I want it.
I know I can use "myMatrix(1,1) = 10" and so on, but I think there must
be a better way.
I also know that I can use a hidden sheet and then just copy the data
from the sheet to the matrix, but i'd like a only VBA code solution.

Can something like this be done?
Regards,


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Populate a matrix, How?

Alan,

How do your read the values from that? I get errors with anything
like:

Msgbox myMatrix(1,1)

Bernie
MS Excel MVP

"Alan Beban" wrote in message
...
Dim myMatrix As Variant
myMatrix = Array(Array(10, 100), Array(20, 200), Array(30, 300))

Alan Beban

Beto wrote:
Hi,
I'm trying to populate a matrix but I can't figure it out a better

way.

Example matrix:

[ 10 100 ]
[ 20 200 ]
[ 30 300 ]

I want a similar way to this: (that does not work)

Dim myMatrix As Variant
ReDim myMatrix(1 To 3, 1 To 2)
myMatrix = Array(Array(10, 20, 30), Array(100,200,300))

This redimensions the matrix to a 6 element array, so is not

working as
I want it.
I know I can use "myMatrix(1,1) = 10" and so on, but I think

there must
be a better way.
I also know that I can use a hidden sheet and then just copy the

data
from the sheet to the matrix, but i'd like a only VBA code

solution.

Can something like this be done?
Regards,




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Populate a matrix, How?

Bernie,

It's like the JavaScript multi-dimension arrays

MsgBox myMatrix(1)(1)

Regards

Bob

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Alan,

How do your read the values from that? I get errors with anything
like:

Msgbox myMatrix(1,1)

Bernie
MS Excel MVP

"Alan Beban" wrote in message
...
Dim myMatrix As Variant
myMatrix = Array(Array(10, 100), Array(20, 200), Array(30, 300))

Alan Beban

Beto wrote:
Hi,
I'm trying to populate a matrix but I can't figure it out a better

way.

Example matrix:

[ 10 100 ]
[ 20 200 ]
[ 30 300 ]

I want a similar way to this: (that does not work)

Dim myMatrix As Variant
ReDim myMatrix(1 To 3, 1 To 2)
myMatrix = Array(Array(10, 20, 30), Array(100,200,300))

This redimensions the matrix to a 6 element array, so is not

working as
I want it.
I know I can use "myMatrix(1,1) = 10" and so on, but I think

there must
be a better way.
I also know that I can use a hidden sheet and then just copy the

data
from the sheet to the matrix, but i'd like a only VBA code

solution.

Can something like this be done?
Regards,






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Populate a matrix, How?

Bob,

Thanks!

Now, how do you read the dimensions? : )

TIA,
Bernie
MS Excel MVP who-learns-something-new-every-day

It's like the JavaScript multi-dimension arrays

MsgBox myMatrix(1)(1)






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Populate a matrix, How?

I figured it out. For example:

MsgBox UBound(myMatrix) - LBound(myMatrix) + 1 & " by " & _
UBound(myMatrix(0)) - LBound(myMatrix(0)) + 1 & " Matrix"

HTH,
Bernie
MS Excel MVP

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Bob,

Thanks!

Now, how do you read the dimensions? : )

TIA,
Bernie
MS Excel MVP who-learns-something-new-every-day

It's like the JavaScript multi-dimension arrays

MsgBox myMatrix(1)(1)






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Populate a matrix, How?

myMatrix(0)(0) = 10
myMatrix(0)(1) = 100
myMatrix(1)(0) = 20
myMatrix(1)(1) = 200
myMatrix(2)(0) = 30
myMatrix(2)(1) = 300

Lbound(myMatrix) = 0
UBound(myMatrix) = 2

LBound(myMatrix(0))= 0
UBound(myMatrix(0))= 1
LBound(myMatrix(1))= 0
UBound(myMatrix(1))= 1
LBound(myMatrix(2))= 0
UBound(myMatrix(2))= 1

Alan Beban

Bernie Deitrick wrote:
Alan,

How do your read the values from that? I get errors with anything
like:

Msgbox myMatrix(1,1)

Bernie
MS Excel MVP

"Alan Beban" wrote in message
...

Dim myMatrix As Variant
myMatrix = Array(Array(10, 100), Array(20, 200), Array(30, 300))

Alan Beban

Beto wrote:

Hi,
I'm trying to populate a matrix but I can't figure it out a better


way.

Example matrix:

[ 10 100 ]
[ 20 200 ]
[ 30 300 ]

I want a similar way to this: (that does not work)

Dim myMatrix As Variant
ReDim myMatrix(1 To 3, 1 To 2)
myMatrix = Array(Array(10, 20, 30), Array(100,200,300))

This redimensions the matrix to a 6 element array, so is not


working as

I want it.
I know I can use "myMatrix(1,1) = 10" and so on, but I think


there must

be a better way.
I also know that I can use a hidden sheet and then just copy the


data

from the sheet to the matrix, but i'd like a only VBA code


solution.

Can something like this be done?
Regards,





  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default Populate a matrix, How?

Alan Beban wrote:

Dim myMatrix As Variant
myMatrix = Array(Array(10, 100), Array(20, 200), Array(30, 300))


Thanks, I'll give it a try!

Regards,
--
Beto
Reply: Erase between the dot (inclusive) and the @.
Responder: Borra la frase obvia y el punto previo.

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default Populate a matrix, How?

Just one way that I would do it...

Dim v
v = [{10,100;20,200;30,300}]

HTH.
--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =


"Beto" wrote in message
...
Hi,
I'm trying to populate a matrix but I can't figure it out a better way.

Example matrix:

[ 10 100 ]
[ 20 200 ]
[ 30 300 ]

I want a similar way to this: (that does not work)

Dim myMatrix As Variant
ReDim myMatrix(1 To 3, 1 To 2)
myMatrix = Array(Array(10, 20, 30), Array(100,200,300))

This redimensions the matrix to a 6 element array, so is not working as
I want it.
I know I can use "myMatrix(1,1) = 10" and so on, but I think there must
be a better way.
I also know that I can use a hidden sheet and then just copy the data
from the sheet to the matrix, but i'd like a only VBA code solution.

Can something like this be done?
Regards,
--
Beto
Reply: Erase between the dot (inclusive) and the @.
Responder: Borra la frase obvia y el punto previo.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I transpose nXm matrix to mXn Matrix MIHir Excel Worksheet Functions 2 August 9th 08 11:44 AM
matrix [email protected] Excel Worksheet Functions 2 February 14th 06 08:53 PM
Matrix Attempt at solving a Matrix Problem? Excel Discussion (Misc queries) 2 August 15th 05 12:39 AM
BCG matrix Anneke Charts and Charting in Excel 1 August 10th 05 09:02 PM
Matrix Basil Charts and Charting in Excel 7 March 3rd 05 02:49 AM


All times are GMT +1. The time now is 02:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"