Simple lookup is not so simple

nimakharrazi

New Member
Joined
Jan 15, 2013
Messages
2
I have two columns of data. Column A has 7,000 names and Column B has 1,500. I need to compare the two and delete all the names in Column A that don't have a match in Column B. How do I do this?

Thank you in advance!
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Maybe:

Code:
Sub nimakharrazi()
Dim lr As Long
Dim rcell As Range
lr = Cells(Rows.Count, 1).End(xlUp).Row

Columns("B:B").Insert xlToRight

With Range("B2:B" & lr)

    .Formula = "=VLOOKUP(A2,$C$2:$C$1000,1,FALSE)"
    .Value = .Value
    
End With

For Each rcell In Range("B2:B" & lr)

    If rcell.Text = "#N/A" Then
    
        rcell.Offset(, -1).Clear
        
    End If
    
Next rcell

Columns("B:B").Delete xlToLeft

For Each rcell In Range("A2:A" & lr)

    If rcell.Value = "" Then
    
        rcell.Delete xlUp
        
    End If
    
Next rcell


End Sub
 
Upvote 0
That worked beautifully! Thank you John!

Maybe:

Code:
Sub nimakharrazi()
Dim lr As Long
Dim rcell As Range
lr = Cells(Rows.Count, 1).End(xlUp).Row

Columns("B:B").Insert xlToRight

With Range("B2:B" & lr)

    .Formula = "=VLOOKUP(A2,$C$2:$C$1000,1,FALSE)"
    .Value = .Value
    
End With

For Each rcell In Range("B2:B" & lr)

    If rcell.Text = "#N/A" Then
    
        rcell.Offset(, -1).Clear
        
    End If
    
Next rcell

Columns("B:B").Delete xlToLeft

For Each rcell In Range("A2:A" & lr)

    If rcell.Value = "" Then
    
        rcell.Delete xlUp
        
    End If
    
Next rcell


End Sub
 
Upvote 0

Forum statistics

Threads
1,215,761
Messages
6,126,735
Members
449,334
Latest member
moses007

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top