I have two sheets with a basic structure: Sheet(A) and Sheet(B). Sheet(B) is a subset from sheet(A) that needs to be removed from Sheet(A). How can this be done in Excel 2007?

link|improve this question

50% accept rate
2  
feedback

1 Answer

Edited the comment's code to work across sheets; this will compare sheet 1 Column A to sheet 2 column A and remove duplicates from sheet 1

Sub removematches()
Dim firstcolumn() As Variant
Dim A As Range
Dim B As Range
Dim i As Long, del As Long

'This will set the ranges to look in.  
Set A = Range("A:A")
Set B = Range("Sheet2!A:A")

firstcolumn = A

ReDim Preserve firstcolumn(1 To UBound(firstcolumn), 1 To 2) As Variant
i = 1
del = 0

Do While i <= UBound(firstcolumn)
    firstcolumn(i, 2) = Application.WorksheetFunction.CountIf(B, firstcolumn(i, 1))
    If firstcolumn(i, 2) > 0 Then
        Range("A1").Offset(i - del - 1, 0).Delete Shift:=xlUp
        del = del + 1
    End If
    i = i + 1
Loop
End Sub
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.