Option Explicit
Sub Filter()
Dim rng1, rng2, rng3, rng4, rng5, rng6, rng7, rng8, _
rng9, rng10, rng11, rng12, rng13, rng14, cell, fndRng As Range
Dim Start, Finish As Worksheet
Dim nrow, col As Long
Dim Val As String
Application.ScreenUpdating = False
Sheets("Input").Range("A2:B5000").ClearContents
Set Start = Sheets("Input"): Set Finish = Sheets("Output")
With Start
Set rng1 = .Range("E8:E" & .Cells(Rows.Count, "E").End(xlUp).Row)
Set rng2 = .Range("J8:J" & .Cells(Rows.Count, "J").End(xlUp).Row)
Set rng3 = .Range("O8:O" & .Cells(Rows.Count, "O").End(xlUp).Row)
Set rng4 = .Range("U8:U" & .Cells(Rows.Count, "U").End(xlUp).Row)
Set rng5 = .Range("Z8:Z" & .Cells(Rows.Count, "Z").End(xlUp).Row)
Set rng6 = .Range("AF8:AF" & .Cells(Rows.Count, "AF").End(xlUp).Row)
Set rng7 = .Range("AL8:AL" & .Cells(Rows.Count, "AL").End(xlUp).Row)
Set rng8 = .Range("AQ8:AQ" & .Cells(Rows.Count, "AQ").End(xlUp).Row)
Set rng9 = .Range("AU8" & .Cells(Rows.Count, "AU").End(xlUp).Row)
Set rng10 = .Range("AV8" & .Cells(Rows.Count, "AV").End(xlUp).Row)
Set rng11 = .Range("AZ8" & .Cells(Rows.Count, "AZ").End(xlUp).Row)
Set rng12 = .Range("BA8" & .Cells(Rows.Count, "BA").End(xlUp).Row)
Set rng13 = .Range("BE8" & .Cells(Rows.Count, "BE").End(xlUp).Row)
Set rng14 = .Range("BF8" & .Cells(Rows.Count, "BF").End(xlUp).Row)
For Each cell In Union(rng1, rng2, rng3, rng4, rng5, rng6, rng7, _
rng8, rng9, rng10, rng11, rng12, rng13, rng14)
Val = cell.Offset(, -1)
If cell = "1" Then
col = cell.Column
With Finish
With .Range("B:B")
Set fndRng = .Find(Val, LookIn:=xlValues, lookat:=xlWhole)
End With
If fndRng Is Nothing Then
nrow = .Cells(Rows.Count, "A").End(xlUp).Row + 1
.Range("A" & nrow) = Start.Cells(1, col - 1)
.Range("B" & nrow) = cell.Offset(0, -1)
End If
End With
ElseIf cell = "0" Then
With Finish
With .Range("B:B")
Set fndRng = .Find(Val, LookIn:=xlValues, lookat:=xlWhole)
End With
If Not fndRng Is Nothing Then
fndRng.EntireRow.Delete
End If
End With
End If
Next cell
End With
Application.ScreenUpdating = True
End Sub
-------
Bookmarks