0% found this document useful (0 votes)
9 views1 page

Useful Macro Kaly

Macro

Uploaded by

Krishna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Useful Macro Kaly

Macro

Uploaded by

Krishna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 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