Public Sub subCombineWorksheets()
Dim strWorksheets As String
Dim arr() As String
Dim i As Integer
Dim rngData As Range
Dim lngLastRow As Long
Dim lngLastColumn As Long
Dim strMsg As String
On Error GoTo Err_Handler
Worksheets("Summary").Cells.Clear
strWorksheets = "A,B,C"
arr = Split(strWorksheets, ",")
lngLastColumn = Worksheets(arr(0)).Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
Worksheets(arr(0)).Range("A1").Resize(1, lngLastColumn).Copy Destination:=Worksheets("Summary").Range("A1")
For i = LBound(arr) To UBound(arr)
lngLastRow = Worksheets(arr(i)).Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
lngLastColumn = Worksheets(arr(i)).Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
Set rngData = Worksheets(arr(i)).Cells(2, 1).Resize(lngLastRow - 1, lngLastColumn)
lngLastRow = Worksheets("Summary").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
rngData.Copy Destination:=Worksheets("Summary").Range("A" & lngLastRow + 1)
strMsg = strMsg & arr(i) & vbCrLf
Next i
With Worksheets("Summary")
.ListObjects.Add(xlSrcRange, Range("A1").CurrentRegion, , xlYes).Name = "SummaryTable"
.ListObjects(1).HeaderRowRange.Font.Color = vbBlack
.Range("A1").CurrentRegion.EntireColumn.AutoFit
End With
strMsg = "The following worksheets have been copied to the Summary worksheet." & vbCrLf & vbCrLf & strMsg
MsgBox strMsg, vbInformation, "Confirmation"
Exit_Handler:
Exit Sub
Err_Handler:
strMsg = "There has been an error." & vbCrLf & vbCrLf & "Error Number : " & Err.Number & vbCrLf & "Description : " & Err.Description
MsgBox strMsg, vbInformation, "Error"
Resume Exit_Handler
End Sub