Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default Multi Dimensional Array

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Multi Dimensional Array

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

--
Regards,
Tom Ogilvy


"steve" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default Multi Dimensional Array

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

"Tom Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy


"steve" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default Multi Dimensional Array

Tom,

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

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

Works Great!
Thanks a lot,
Steve

"Tom Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy


"steve" wrote:

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Multi Dimensional Array

unfortunately Typos are my trademark :-{

sorry for the misinformation and glad you figured it out.

--
Regards,
Tom Ogilvy


"steve" wrote:

Tom,

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

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

Works Great!
Thanks a lot,
Steve

"Tom Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy


"steve" wrote:

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

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
Multi Dimensional Array andym Excel Programming 11 July 10th 06 05:09 AM
Multi-Dimensional Array Let & Get Trip[_3_] Excel Programming 0 September 21st 05 08:41 PM
Viewing Multi dimensional array Codea[_2_] Excel Programming 0 August 5th 04 12:49 PM
Enumerating a multi-dimensional array Robert Stober Excel Programming 7 September 13th 03 12:28 PM
Problem with Multi-Dimensional Array Kirk[_2_] Excel Programming 2 August 26th 03 03:31 PM


All times are GMT +1. The time now is 06:08 AM.

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

About Us

"It's about Microsoft Excel"