So, I have a workbook with a varying number of sheets. All have the same structure, number of columns, headers. What I want to do is put all the sheets together in 1 sheet. I've tried several codes but this one is the only one that doesn't give me an error message. However, it's only pasting the header lines and not pasting any of the data. But I want only 1 header line AND all the data from the other sheets in the master sheet. Can anyone help???
VBA Code:
Sub CopyFromWorksheets()
Dim wrk As Workbook 'Workbook object
Dim sht As Worksheet
Dim trg As Worksheet
Dim rng As Range
Dim colCount As Integer
Set wrk = ActiveWorkbook
Application.ScreenUpdating = False
Set trg = wrk.Worksheets.Add(After:=wrk.Worksheets(wrk.Worksheets.count))
trg.name = "Master"
Set sht = wrk.Worksheets(1)
colCount = sht.Cells(1, 255).End(xlToLeft).Column
With trg.Cells(1, 1).Resize(1, colCount)
.Value = sht.Cells(1, 1).Resize(1, colCount).Value
'Set font as bold
.Font.Bold = True
End With
For Each sht In wrk.Worksheets
If sht.Index = wrk.Worksheets.count Then
Exit For
End If
Set rng = sht.Range(sht.Cells(2, 1), sht.Cells(65536, 1).End(xlUp).Resize(, colCount))
trg.Cells(65536, 1).End(xlUp).Offset(1).Resize(rng.ROWS.count, rng.Columns.count).Value = rng.Value
Next sht
Application.ScreenUpdating = True
End Sub