Option Explicit
Public Sub ClearSheet1()
Dim s1 As Worksheet
Dim s2 As Worksheet
Set s1 = ActiveWorkbook.Sheets(1)
Set s2 = ActiveWorkbook.Sheets(2)
Dim s1Row As Integer: s1Row = 1
While s1.Cells(s1Row, 1).FormulaR1C1 <> ""
Dim id As String: id = s1.Cells(s1Row, 1).FormulaR1C1
If IsPresent(s2, id) Then
s1.Rows(CStr(s1Row) & ":" & CStr(s1Row)).Delete Shift:=xlUp
Else
s1Row = s1Row + 1
End If
Wend
End Sub
Public Function IsPresent(s As Worksheet, id As String) As Boolean
Dim row As Integer: row = 1
Dim result As Boolean: result = False
Do While s.Cells(row, 1).FormulaR1C1 <> ""
If s.Cells(row, 1).FormulaR1C1 = id Then
result = True
Exit Do
End If
row = row + 1
Loop
IsPresent = result
End Function
|