Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

Extract data from multiple worksheets to one sheet using vba

Public Sub ConsolidateData()

' Declare and initialize the destination sheet


Dim destinationSheet As Worksheet
Set destinationSheet = ThisWorkbook.Worksheets("Sheet1")

' Loop through all worksheets in the workbook that is running the script
Dim sourceSheet As Worksheet
For Each sourceSheet In ThisWorkbook.Worksheets
If sourceSheet.Name <> destinationSheet.Name Then

' Set the source sheet's range


Dim sourceRange As Range
Set sourceRange = sourceSheet.UsedRange ' I'm using used range, but you
could leave it as you had it in terms of a fixed range:
sourceSheet.Range("A12:Y60").Copy

' Get first available cell in column A (from bottom to top)


Dim targetCell As Range
Set targetCell = destinationSheet.Range("A" &
destinationSheet.Cells(destinationSheet.Rows.Count, "A").End(xlUp).Row).Offset(1,
0)

' Resize and assign values from source range (using value2 speeeds up
things)
targetCell.Resize(sourceRange.Rows.Count,
sourceRange.Columns.Count).Value2 = sourceRange.Value2

End If
Next sourceSheet

End Sub

You might also like