I have an existing code that cycles through multiple sheets and copies rows with a value in column B and D, but P being empty, to a report sheet. How can I go about getting it to search for all identical values in column D across all sheets and copying to the report sheet while keeping the original code intact? EX: rows 1, 2, and 3 on sheet 1 fulfill the requirements and will be copied to the report sheet. Row 1 on sheet 2 does not fulfill the requirements, but the cell D1 is the same as D1 on sheet 1. I would like it to copy all 4 rows.
Dim wb As Workbook: Set wb = ThisWorkbook
Dim srcSheets As Sheets: Set srcSheets = wb.Sheets(Array("sheet1, sheet2, sheet3, sheet4, sheet5"))
Dim rptSheet As Worksheet: Set rptSheet = wb.Sheets("Report")
Dim rptCell As Range: Set rptCell = rptSheet.Cells(rptSheet.Rows.Count, "A").End(xlUp).Offset(1)
Dim srcSheet As Object, srcRange As Range, srcRow As Range
For Each srcSheet In srcSheets
If TypeOf srcSheet Is Worksheet Then
Set srcRange = srcSheet.Range("A5:N358")
For Each srcRow In srcRange.Rows
If Len(CStr(srcRow.Columns("B").Value)) > 0 And Len(CStr(srcRow.Columns("P").Value)) = 0 And Len(CStr(srcRow.Columns("D").Value)) > 0 Then
srcRow.Copy Destination:=rptCell
Set rptCell = rptCell.Offset(1)
End If
Next srcRow
End If
Next srcSheet