# Thread: Array manipulation Thanks: 0 Likes: 0

1. ## Array manipulation

Hello guys,

I'm trying to take a range from each sheet and add it into array.
The selected ranges will always be the same size so only the first dimension of the array needs to be redimmed

You can use:

Code:
`arrayInQuestion = Range("M1:M30").Value`
To set an array to be equal to a range, but after that im stuck, if i understand correctly its not possible anymore to add a new range into the array?

I have to add it into a second array and then add them together?

Or is it maybe better to select all of the fields i need and only then push them into an array?

2. ## Re: Array manipulation

This will load the range from all sheets to the array...
Code:
```Sub LoadShtArr()
Dim Ar() As Variant, Rng As Range, sht As Worksheet
Dim Cnt As Integer, Cnt2 As Integer, Cnt3 As Integer
Cnt = 0
Cnt2 = 0
For Each sht In ThisWorkbook.Sheets
Cnt = Cnt + 1
ReDim Preserve Ar(Cnt)
With Sheets(sht.Name)
Set Rng = .Range("M1:M30")
End With
Ar(Cnt2) = Rng
Cnt2 = Cnt2 + 1
Next sht
'insert array into sheet1 A1:A30; B1:B30; etc.
'For Cnt3 = LBound(Ar) To UBound(Ar)
'With ThisWorkbook.Sheets("sheet1")
'.Range(.Cells(1, Cnt3 + 1), .Cells(30, Cnt3 + 1)) = Ar(Cnt3)
'End With
'Next Cnt3
End Sub```
U didn't say what/where U wanted the output. The code (if U uncomment the relevant code) will place the array content in sheet1 A1 to whatever. Adjust to suit. If you have more ranges that U are interested in from each sheet, it seems better just to create a new array for each range and follow the code outlined. HTH. Dave

3. ## Re: Array manipulation

Thanks a lot Dave, that is some great code that does exactly what i needed! I ended up cycling through each page and adding 10 variables at a time, this will be a great improvement!

4. ## Re: Array manipulation

You are welcome. Thanks for posting your outcome. Dave