Sub combine()
Dim ws As Worksheet, ws1 As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
Sheets("Combine").Delete
Sheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = "Combine"
Set ws1 = ActiveSheet
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "Combine" Then
If ws1.Application.WorksheetFunction.CountA(Rows(1)) = 0 Then
ws.Rows(2).Copy ws1.Range("A1")
Else
ws.Rows(2).Copy ws1.Range("A" & ws1.Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row)
End If
Dim lcol As Long, lrow As Long, lrow1 As Long
lcol = ws.Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
lrow = ws.Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
lrow1 = ws1.Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row + 1
ws.Range(Cells(3, 1).Address & ":" & Cells(lrow, lcol).Address).Copy ws1.Range("a" & lrow1)
End If
Next ws
ws1.Select
Cells.Select
Selection.EntireColumn.AutoFit
Range("a1").Select
MsgBox ("Done")
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
|