This macro meets your "RULES", but the results have a few more rows than your example results, I believe it is because all 3 sample rows have "YES" in column AY.
Option Explicit
Option Compare Text
Sub CreateExtract()
Dim LR As Long, Rw As Long, NR As Long
Dim OrderNums As String
Dim wsIN As Worksheet, wsOUT As Worksheet
Set wsIN = ThisWorkbook.Sheets("Raw Data")
Set wsOUT = ThisWorkbook.Sheets("Extract")
LR = wsIN.Range("A" & wsIN.Rows.Count).End(xlUp).Row
wsOUT.UsedRange.Offset(1).Clear
NR = 2
For Rw = 2 To LR
'Back
If InStr(wsIN.Range("AM" & Rw).Value, "B") > 0 Then
wsIN.Rows(Rw).Copy wsOUT.Range("A" & NR)
wsOUT.Range("AM" & NR).Value = "Back"
NR = NR + 1
End If
'Round
If InStr(wsIN.Range("AM" & Rw).Value, "R") > 0 Then
wsIN.Rows(Rw).Copy wsOUT.Range("A" & NR)
wsOUT.Range("AM" & NR).Value = "Round"
NR = NR + 1
End If
'Site Clear (only 1 order number per Extract table)
If InStr(OrderNums, wsIN.Range("E" & Rw).Value) = 0 Then
wsIN.Rows(Rw).Copy wsOUT.Range("A" & NR)
wsOUT.Range("AM" & NR).Value = "Site Clear"
OrderNums = OrderNums & "," & wsIN.Range("E" & Rw).Value
NR = NR + 1
End If
'Surplus
If wsIN.Range("AY" & Rw).Value = "YES" Then
wsIN.Rows(Rw).Copy wsOUT.Range("A" & NR)
wsOUT.Range("AM" & NR).Value = "Surplus"
NR = NR + 1
End If
'Dra Rep
If wsIN.Range("BF" & Rw).Value = "YES" Then
wsIN.Rows(Rw).Copy wsOUT.Range("A" & NR)
wsOUT.Range("AM" & NR).Value = "Dra Rep"
NR = NR + 1
End If
'Spec Sur
If wsIN.Range("BH" & Rw).Value = "YES" Then
wsIN.Rows(Rw).Copy wsOUT.Range("A" & NR)
wsOUT.Range("AM" & NR).Value = "Spec Sur"
NR = NR + 1
End If
Next Rw
End Sub
Bookmarks