![]() |
3 dimensional array
I am trying to self learn vba and at this point I am dabbling with arrays. I
have a command button on sheet Array1 called cmd3dArray, also on this sheet I have data a, b, c, etc in cells A1:E5. In the next sheet Array2 I have data in A1:E5 namely a1, b1, c1 etc and similarly in sheet Array3, a2, b2 etc. I am trying to collect the data from the three sheets into a 3-dimensional array - I'm struggling - any offers. Sandy |
3 dimensional array
One way:
Option Explicit Sub testme() Dim wCtr As Long Dim iCol As Long Dim iRow As Long Dim myArray(1 To 5, 1 To 5, 1 To 3) As Variant 'rows x cols x sheets For wCtr = 1 To 3 For iRow = 1 To 5 For iCol = 1 To 5 myArray(iRow, iCol, wCtr) _ = Worksheets("array" & wCtr).Cells(iRow, iCol).value Next iCol Next iRow Next wCtr End Sub Sandy wrote: I am trying to self learn vba and at this point I am dabbling with arrays. I have a command button on sheet Array1 called cmd3dArray, also on this sheet I have data a, b, c, etc in cells A1:E5. In the next sheet Array2 I have data in A1:E5 namely a1, b1, c1 etc and similarly in sheet Array3, a2, b2 etc. I am trying to collect the data from the three sheets into a 3-dimensional array - I'm struggling - any offers. Sandy -- Dave Peterson |
3 dimensional array
I don't understand why you want a 3 dimentioned array. Perhaps a two
dimentioned array with the first index to indicate which of the 3 sheets: Dim c, i Dim MyArray(3, 25) i = 0 For Each c In Worksheets("Array1").Range("A1:E5") MyArray(1, i) = c i = i + 1 Next c i = 0 For Each c In Worksheets("Array2").Range("A1:E5") MyArray(2, i) = c i = i + 1 Next c i = 0 For Each c In Worksheets("Array3").Range("A1:E5") MyArray(2, i) = c i = i + 1 Next c "Sandy" wrote in message ... ....I have data a, b, c, etc in cells A1:E5. In the next sheet Array2 I have data in A1:E5 namely a1, b1, c1 etc and similarly in sheet Array3, a2, b2 etc. I am trying to collect the data from the three sheets into a 3-dimensional array - I'm struggling - any offers. Sandy |
All times are GMT +1. The time now is 01:48 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com