I have an excel file with 8 sheets and I want to combine the range with data from "adws","chws","homelines","ariel","kit","philip" and "timmy" to the sheet "ws", except the header.
Here is my code:
Private Sub combine_btn_Click()
Dim ws As Worksheet
Dim adws As Worksheet
Dim chws As Worksheet
Dim homelines As Worksheet
Dim ariel As Worksheet
Dim kit As Worksheet
Dim philip As Worksheet
Dim timmy As Worksheet
Dim adws_co As Long
Dim chws_co As Long
Dim homelines_co As Long
Dim ariel_co As Long
Dim kit_co As Long
Dim philip_co As Long
Dim timmy_co As Long
Dim ws_co As Long
Set ws = ThisWorkbook.Sheets("Data")
Set adws = ThisWorkbook.Sheets("SL - Adult")
Set chws = ThisWorkbook.Sheets("SL - Children")
Set homelines = ThisWorkbook.Sheets("Homelines & Acc")
Set ariel = ThisWorkbook.Sheets("Hardlines - Ariel")
Set kit = ThisWorkbook.Sheets("Hardlines - Kit")
Set philip = ThisWorkbook.Sheets("Hardlines - Philip")
Set timmy = ThisWorkbook.Sheets("Hardlines - Timmy")
ws_co = ws.Range("A2:F" & Rows.Count).End(xlDown).Row + 1
adws_co = adws.Range("D2:F" & Rows.Count).End(xlDown).Row + 1
chws_co = chws.Range("D2:F" & Rows.Count).End(xlDown).Row + 1
homelines_co = homelines.Range("D2:F" & Rows.Count).End(xlDown).Row + 1
ariel_co = ariel.Range("D2:F" & Rows.Count).End(xlDown).Row + 1
kit_co = kit.Range("D2:F" & Rows.Count).End(xlDown).Row + 1
philip_co = philip.Range("D2:F" & Rows.Count).End(xlDown).Row + 1
timmy_co = timmy.Range("D2:F" & Rows.Count).End(xlDown).Row + 1
adws.Range("D2:F" & adws_co).SpecialCells(xlCellTypeVisible).Copy
ws.Select
Range("D" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
chws.Range("D2:F" & chws_co).SpecialCells(xlCellTypeVisible).Copy
ws.Select
Range("D" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
homelines.Range("D2:F" &homelines_co).SpecialCells(xlCellTypeVisible).Copy
ws.Select
Range("D" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
ariel.Range("D2:F" & ariel_co).SpecialCells(xlCellTypeVisible).Copy
ws.Select
Range("D" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
kit.Range("D2:F" & kit_co).SpecialCells(xlCellTypeVisible).Copy
ws.Select
Range("D" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
philip.Range("D2:F" & philip_co).SpecialCells(xlCellTypeVisible).Copy
ws.Select
Range("D" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
timmy.Range("D2:F" & timmy_co).SpecialCells(xlCellTypeVisible).Copy
ws.Select
Range("D" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
However, when the sheet "philip" is empty, I received a failure "Method 'Range' of object '_Worksheet' failed on this line:
philip.Range("D2:F" & philip_co).SpecialCells(xlCellTypeVisible).Copy
May I know is there any way to solve it? Thanks in advance!