Multi Dimensional Array

S

steve

I found a post on here about putting contents of an Array into a cell. The
solution was to use the Join Function. I had the same question, but my Array
is multi-dimensional. I've found that the join function only works for
1-dimensional arrays. Below is some code I came up with for
multi-dimensional arrays, but it seems like there might be a better way.
Also, how would I take the string (with comma delimiters) and put it back
into a multi-dimensional array?

Dim intI As Integer, intJ As Integer
Dim rng As Range
Dim BlackAArray(1 To 10, 1 To 4) As Variant

Set rng = Worksheets("Calculations").Range("BlackAMatrix")

For intI = 1 To 10
For intJ = 1 To 4
BlackAArray(intI, intJ) = rng.Cells(intI, intJ)
Next intJ
Next intI

Worksheets("Calculations").Range("M1").Value = ""

For intI = 1 To 10
For intJ = 1 To 4
If intI = 10 And intJ = 4 Then
Worksheets("Calculations").Range("M1").Value =
Worksheets("Calculations").Range("M1").Value & BlackAArray(intI, intJ)
Else
Worksheets("Calculations").Range("M1").Value =
Worksheets("Calculations").Range("M1").Value & BlackAArray(intI, intJ) & ", "
End If
Next intJ
Next intI


thanks,
Steve
 
T

Tom Ogilvy

Dim intI As Integer, intJ As Integer
Dim rng As Range, s as String

Set rng = Worksheets("Calculations").Range("BlackAMatrix")

For intI = 1 To 10
For intJ = 1 To 4
s = s & rng.Cells(intI, intJ) & ", "
Next intJ
Next intI

Worksheets("Calculations").Range("M1").Value = Left(s,len(s)-2)

---------------------------------
---------------------------------
Dim intI as Long, intJ as Long, v as Variant
Dim rng as Range
Set rng = Worksheets("Calculations").Range("BlackAMatrix")
v = split(Worksheets("Calculations").Range("M1").Value,", ")
rw = lbound(v)
for intI = 1 to 10
for intj = 1 to 4
rng(i,j) = v(rw)
rw = rw + 1
Next
Next
 
S

steve

Tom,

Thanks for the quick reply! The first part works great. When I run the
second part, it pastes the value from (intI = 10, intJ = 4). Also, it
doesn't paste it to BlackAMatrix range. it pastes it (-1, -1) from
BlackAMatrix.

I'm trying to understand what you did. what does LBound(v) do?

Thanks!
Steve
 
S

steve

Tom,

You had a small typo:
rng(i,j) = v(rw)

should be:
rng(intI, intJ) = v(rw)

Works Great!
Thanks a lot,
Steve
 
T

Tom Ogilvy

unfortunately Typos are my trademark :-{

sorry for the misinformation and glad you figured it out.
 

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