Currently I have a workbook with about 15 tabs with 100s of rows each. I only want to combine 10. The code below works for me if I remove the 5 tabs I dont want but is there a way to adjust this to define the tabs I want to combine? Better yet a dialog box to pick which tabs?
Sub CombineWorksheetsIntoOne()
Application.ScreenUpdating = False
Dim wb As Workbook
Dim ws As Worksheet
Dim ms As Worksheet
Dim rng As Range
Dim colCount As Integer
Set wb = ActiveWorkbook
Set ms = wb.Worksheets.Add(After:=wb.Worksheets(wb.Worksheets.Count))
ms.Name = "Main"
Set ws = wb.Worksheets(1)
colCount = ws.Cells(1, 255).End(xlToLeft).Column
With ms.Cells(1, 1).Resize(1, colCount)
.Value = ws.Cells(1, 1).Resize(1, colCount).Value
.Font.Bold = True
End With
For Each ws In wb.Worksheets
If ws.Index = wb.Worksheets.Count Then
Exit For
End If
Set rng = ws.Range(ws.Cells(2, 1), ws.Cells(65536, 1).End(xlUp).Resize(, colCount))
ms.Cells(65536, 1).End(xlUp).Offset(1).Resize(rng.Rows.Count, rng.Columns.Count).Value = rng.Value
Next ws
ms.Columns.AutoFit
Application.ScreenUpdating = True
End Sub
Sub CombineWorksheetsIntoOne()
Application.ScreenUpdating = False
Dim wb As Workbook
Dim ws As Worksheet
Dim ms As Worksheet
Dim rng As Range
Dim colCount As Integer
Set wb = ActiveWorkbook
Set ms = wb.Worksheets.Add(After:=wb.Worksheets(wb.Worksheets.Count))
ms.Name = "Main"
Set ws = wb.Worksheets(1)
colCount = ws.Cells(1, 255).End(xlToLeft).Column
With ms.Cells(1, 1).Resize(1, colCount)
.Value = ws.Cells(1, 1).Resize(1, colCount).Value
.Font.Bold = True
End With
For Each ws In wb.Worksheets
If ws.Index = wb.Worksheets.Count Then
Exit For
End If
Set rng = ws.Range(ws.Cells(2, 1), ws.Cells(65536, 1).End(xlUp).Resize(, colCount))
ms.Cells(65536, 1).End(xlUp).Offset(1).Resize(rng.Rows.Count, rng.Columns.Count).Value = rng.Value
Next ws
ms.Columns.AutoFit
Application.ScreenUpdating = True
End Sub