vba collate each sheets data into Master using Redim Preserve Array

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team

I have 5 sheets of which 4 sheets contains data and each sheets has 10 columns.

My task is to add each sheets data into array using Redim Preserve

and Paste in Master sheets range ("A1")

Thanks in advance for your help!

Option Explicit
VBA Code:
Sub Array_Two_Dimension_With()
    Dim arr() As Variant
    Dim Master_sht As Worksheet
    Dim check As Boolean
    Dim sh As Worksheet
    
    Dim file As Long
    Dim lr As Long
        
    For Each sh In ThisWorkbook.Worksheets
        If sh.Name <> "Master" Then
                file = file + 1
            If file = 1 Then
                arr = sh.Range("a1").CurrentRegion.Value
            Else
                arr = sh.Range("a1").CurrentRegion.Offset(1).Resize(lr - 1) 'Exclude Header
            End If
        End If
        
    Next sh

sheets("Master").range("a1").resize(ubound(arr),ubound(arr).value = arr   paste stored arrays values in Master sheet.

End Sub


Thanks
mg
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,215,040
Messages
6,122,806
Members
449,095
Latest member
m_smith_solihull

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