Question : Excel macro that would delete rows if ID numbers match

I have an Excel workbook with two worksheets containing name-and-address data.  In both worksheets, the first column contains ID numbers.  I'd like a macro that deletes the row from the FIRST worksheet if there is a matching ID number in the SECOND worksheet.

One possible way to do this would be to append the data from the second worksheet to the first worksheet and then delete BOTH rows if there is a duplicate pair.

Thanks in advance for any help.

Answer : Excel macro that would delete rows if ID numbers match

This will do the job:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
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
Random Solutions  
 
programming4us programming4us