Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Multi Dimensional Array | Excel Programming | |||
Multi-Dimensional Array Let & Get | Excel Programming | |||
Viewing Multi dimensional array | Excel Programming | |||
Enumerating a multi-dimensional array | Excel Programming | |||
Problem with Multi-Dimensional Array | Excel Programming |