VBA add to Array with multiple CurrentRegion ranges

Boffa

New Member
Joined
May 8, 2019
Messages
27
HI Guys,

I know how to add to an array using the Range.CurrentRegion, but what if you have a range of data across multiple sheets ?
Is it possible to loop through each sheet and add to the array using range.CurrentRegion on each sheet, without over-riding what's already existing in the array, but instead just appending ?

Below is my code which is over-riding the data in the array on each loop
Any help much appreciated


VBA Code:
  ReDim arr(1 To Sheets.Count - 2, 1 To 5)
    For Each ws In Sheets
        If ws.Tab.Color <> vbBlue Then
           arr = ws.Range("a1").CurrentRegion.Offset(1).Resize(ws.Range("a1").CurrentRegion.rows.Count - 1)
        End If
    Next ws
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi
An option to use jugged array
EX:
VBA Code:
Sub test()
 ReDim arr(1 To Sheets.Count - 2)
 i = 1
    For Each ws In Sheets
        If ws.Tab.Color <> vbBlue Then
           arr(i) = ws.Range("a1").CurrentRegion.Offset(1).Resize(ws.Range("a1").CurrentRegion.Rows.Count - 1)
           i = i + 1
        End If
    Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,843
Members
449,193
Latest member
MikeVol

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top