I have a workbook with 8 worksheets in it and I need to be able to combine 4 of the worksheets into one worksheet. Each worksheet has a name other than Sheet1, Sheet2 and so on. All four worksheets have the same number of columns but have a different number of rows in each. The number of rows in each worksheet is dynamic. Below is some code that I have adapted from combining 2 worksheets together (the code for just combining two worksheets together works great). I have been able to get it to only combine two of the four worksheets that I need. I am sure that I am missing something simple and would appreciate it if someone would be able to show me what it is that i am missing to make this macro combine all four worksheets?
Sub Combine_Four_Tabs()
Dim lngLastRow As Long
lngLastRow = Sheets("Friends").Range("A65536").End(xlUp).Row
If lngLastRow > 1 Then
Sheets("Friends").Range("A2:AN" & lngLastRow).ClearContents
End If
lngLastRow = Sheets("Ned").Range("A65536").End(xlUp).Row
Sheets("Ned").Range("A2:AN" & lngLastRow).Copy Sheets("Friends").Range("A2")
lngLastRow = Sheets("Sam").Range("A65536").End(xlUp).Row
Sheets("Sam").Range("A2:AN" & lngLastRow).Copy
Sheets("Friends").Select
lngLastRow = Sheets("John").Range("A65536").End(xlUp).Row
Sheets("John").Range("A2:AN" & lngLastRow).Copy
Sheets("Friends").Select
lngLastRow = Sheets("Fred").Range("A65536").End(xlUp).Row
Sheets("Fred").Range("A2:AN" & lngLastRow).Copy
Sheets("Friends").Select
Range("A65536").End(xlUp).Offset(1, 0).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Columns("A:A").Select
Selection.Replace What:="0", Replacement:="", LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
ReplaceFormat:=False
Range("A1").Select
End Sub
Thanks in advance for your help.
Sub Combine_Four_Tabs()
Dim lngLastRow As Long
lngLastRow = Sheets("Friends").Range("A65536").End(xlUp).Row
If lngLastRow > 1 Then
Sheets("Friends").Range("A2:AN" & lngLastRow).ClearContents
End If
lngLastRow = Sheets("Ned").Range("A65536").End(xlUp).Row
Sheets("Ned").Range("A2:AN" & lngLastRow).Copy Sheets("Friends").Range("A2")
lngLastRow = Sheets("Sam").Range("A65536").End(xlUp).Row
Sheets("Sam").Range("A2:AN" & lngLastRow).Copy
Sheets("Friends").Select
lngLastRow = Sheets("John").Range("A65536").End(xlUp).Row
Sheets("John").Range("A2:AN" & lngLastRow).Copy
Sheets("Friends").Select
lngLastRow = Sheets("Fred").Range("A65536").End(xlUp).Row
Sheets("Fred").Range("A2:AN" & lngLastRow).Copy
Sheets("Friends").Select
Range("A65536").End(xlUp).Offset(1, 0).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Columns("A:A").Select
Selection.Replace What:="0", Replacement:="", LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
ReplaceFormat:=False
Range("A1").Select
End Sub
Thanks in advance for your help.