Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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
End Sub
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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