VBA Query for skipping space and header from multiple sheet while consolidating data (from multiple sheets into 1 sheet of same excel)

syprakash

New Member
Joined
Sep 15, 2010
Messages
6
I am using below code to extract & consolidate data from multiple sheets into 1 new sheet of same excel file.
But this Macro copying all rows from all sheets. I want to extract only active data (want to stop extracting when there is no data (space/empty) in Column 'A', and move into next sheet (or tab) for extraction.

Also i want to skip copying header row(1st row) from each sheet (tab).

Could you please share me code for the same.

Code:
Sub Combine()
    Dim I As Long
    Dim xRg As Range
    On Error Resume Next
    Worksheets.Add Sheets(1)
    ActiveSheet.Name = "Combined"
   For I = 2 To Sheets.Count
        Set xRg = Sheets(1).UsedRange
        If I > 2 Then
            Set xRg = Sheets(1).Cells(xRg.Rows.Count + 1, 1)
        End If
        Sheets(I).Activate
        ActiveSheet.UsedRange.Copy xRg
    Next
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try:
Code:
Sub Combine()
    
    Dim w   As Long
    Dim x   As Long
    Dim y   As Long
    
    Application.ScreenUpdating = False
    
    y = sheets(1).Cells(1, Columns.Count).End(xlToLeft).Column
    Worksheets.Add sheets(1)
    With ActiveSheet
        .Name = "Combined"
        .Cells(1, 1).Resize(, y).Value = sheets(2).Cells(1, 1).Resize(, y).Value
    End With
    
    For w = 2 To sheets.Count
        With sheets(w)
            y = .Cells.Find(What:="*", after:=.Cells(1, 1), SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
            x = .Cells(.Rows.Count, 1).End(xlUp).Row - 1
            sheets(1).Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(x, y).Value = .Cells(2, 1).Resize(x, y).Value
        End With
    Next w
    
    Application.ScreenUpdating = True
    
End Sub
 
Last edited:
Upvote 0
Still it copies entire data from each sheet, I want to stop extracting in particular tab when there is no data (space/empty) in Column 'A'(even some data left out after empty row), and move into next sheet (or tab) for extraction.
 
Upvote 0

Forum statistics

Threads
1,216,076
Messages
6,128,670
Members
449,463
Latest member
Jojomen56

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