Hello - I have code (below) that reads through a set of .xlsm files in a folder and captures the date/time stamp and a count. The code works fine, except for two items:

1) There is a '#_ROW_DATA_END' record at the end of each file that gets written to my output worksheet that I would like to prevent. I've experimented with some 'If' statements, but I keep getting a 'Invalid or unqualified reference' error (I've stripped out those attempts in the code below).

2) Also, the current code continues to append records to 'Sheet2' when the code is running repetitively:

Sub GetWbStatHrlyData()
Dim mydir As String: mydir = "C:\Users\ptdooley\OneDrive - Commonwealth of Massachusetts\HIX_Materials\HIX_WebStats\Webstats_Rpts\WebstatsRpt_TEST\WebstatsHrly_TEST\" 'Change directory as needed. Note that it must be closed with "\"
Dim myFile As String
Dim wb As Workbook
Dim temp, temp2
myFile = Dir(mydir & "*.xlsm")
Do While Len(myFile) > 0
    Set wb = Workbooks.Open(mydir & myFile)
    With wb.Sheets("MAHIX_Individual_Site_Unique_Vi")
        temp = .Range("A16:B" & .Cells(Rows.Count, "A").End(xlUp).Row).Value
    End With
    With ThisWorkbook.Sheets("Sheet2")
     
        lRow = .Cells(Rows.Count, "B").End(xlUp).Row + 1
        .Cells(lRow, "B").Resize(UBound(temp), 2) = temp
        .Cells(lRow, "A").Resize(UBound(temp)).Value = wb.Name
        .Cells(lRow, "B").Resize(UBound(temp)).NumberFormat = "MM/dd/yyyy hh:mm"
    End With
    wb.Close False
    myFile = Dir()
Loop
End Sub
What do I need to add here to prevent the writing out of any row that contains the string ''#_ROW_DATA_END', but still captures the other records in the file? And what do I need to properly clear out any existing records before the next execution of the code which will write out the current records?

Thank you!