WE can apply an AUTOFILTER to the source workbooks. Since we're copying from row 9 down, this means we can use row 8 for the "filter". So, you want to filter everything out that is blank in column D?
Option Explicit
Sub ROIConsolidation()
Dim wsMstr As Worksheet, wb As Workbook
Dim fPATH As String, fNAME As String, NR As Long, LR As Long
Set wsMstr = ThisWorkbook.Sheets("Data") 'macro stored in master workbook
fPATH = "C:\Individual Trackers\" 'edit as needed, remember the final \ in this string
If MsgBox("Clear current data sheet", vbYesNo) = vbYes Then 'option to clear the current master sheet, except headers
wsMstr.UsedRange.Offset(1).Clear
NR = 2
Else 'otherwise we append to old data
NR = wsMstr.Range("A" & Rows.Count).End(xlUp).Row + 1
End If
fNAME = Dir(fPATH & "*.xlsx") 'get the name of the first file in the fPATH
On Error GoTo Next1 'if no ROI sheet is found, will skip the copy commands
Do While Len(fNAME) > 0
Set wb = Workbooks.Open(fPATH & fNAME) 'open the found file
With wb.Sheets("ROI")
.Rows(8).AutoFilter 4, "<>" 'only show rows that are not blank in column D
LR = .Range("D" & .Rows.Count).End(xlUp).Row 'find the last row of data
If LR > 8 Then
.Range("D9:X" & LR).Copy 'copy rows to master sheet
wsMstr.Range("A" & NR).PasteSpecial xlPasteValuesAndNumberFormats 'removes formulas and cell formats
NR = wsMstr.Range("A" & Rows.Count).End(xlUp).Row + 1 'set NR for next paste job
End If
End With
Next1:
wb.Close False 'close found file
fNAME = Dir 'get next filename from fPATH
Loop 'repeat process
End Sub
Bookmarks