Hi,
I have the below code which copies data from several workbooks to a master file. It works perfectly and ignores the header row when there is data in row 2 and below. However, if there is no data in row 2 and below (i.e. blank sheet apart from the headers) it copies the header row. Is there something incorrect in the code? What can I change to make sure it always ignores headers?
I have the below code which copies data from several workbooks to a master file. It works perfectly and ignores the header row when there is data in row 2 and below. However, if there is no data in row 2 and below (i.e. blank sheet apart from the headers) it copies the header row. Is there something incorrect in the code? What can I change to make sure it always ignores headers?
VBA Code:
Sub btnImport_Click()
Application.ScreenUpdating = False
Dim wkbDest As Workbook
Dim wkbSource As Workbook
Set wkbDest = ThisWorkbook
Dim LastRow As Long
Const strPath As String = "P:\Returns\Engineering Jobs\Toms Triage\Process User Forms\"
ChDrive "P"
ChDir strPath
strExtension = Dir("*.xlsm")
Do While strExtension <> ""
Set wkbSource = Workbooks.Open(strPath & strExtension)
With wkbSource
LastRow = .Sheets("Triage").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
With .Sheets("Triage").Range("A2:K" & LastRow)
.Copy wkbDest.Sheets("Triage Master").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
.EntireRow.Delete
End With
.Close savechanges:=True
End With
strExtension = Dir
Loop
Application.ScreenUpdating = True
MsgBox " Import Complete !"
End Sub