Match and replace cell from another sheet

sqi27

New Member
Joined
Aug 13, 2012
Messages
2
Question: I have two sheets named Sheet1 and Sheet2. Sheets looks like this:

Sheet1
A
ab@gmail.com
je@yahoo.com
gy@hotmail.com
ob@outlook.com
vh@hotmail.com
nk@ymail.com

Sheet2
A
ob@outlook.com
je@yahoo.com
nk@ymail.com


Here is what I want: If any cell in Sheet2 Column A = Any cell in Sheet1 Column A, delete sheet1 column A cell value.


How to do it?

Thanks...
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Try this code

Code:
Sub FOO()
Dim LR As Long
Dim rng As Range

LR = Cells(Rows.Count, 1).End(xlUp).Offset(-1).Row

For Each rng In [A2].Resize(LR)
    If Not IsError(Application.Match(rng, Sheets(2).Columns(1), 0)) Then
        rng = vbNullString
    End If
Next rng

Columns(1).SpecialCells(xlCellTypeBlanks).EntireRow.Delete

End Sub
 
Last edited:
Upvote 0
Untested. Try on a copy.

Code:
Sub sqi27()

Dim lr As Long
Dim rcell As Range

Sheets("Sheet1").Activate

lr = Cells(Rows.Count, 1).End(xlUp).Row

Columns("B:B").Insert

With Range("B2:B" & lr)

    .Formula = "=VLOOKUP(A2,Sheet2!A2:A100,1,FALSE)"
    .Value = .Value
    .Replace WHAT:="#N/A", replacement:=""

End With

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

    If rcell.Value <> "" Then rcell.Offset(, -1).Delete shift:=xlUp
    
Next rcell

Columns("B:B").Delete shift:=xlToLeft

End Sub
 
Upvote 0
Works. Thanks.



Try this code

Code:
Sub FOO()
Dim LR As Long
Dim rng As Range

LR = Cells(Rows.Count, 1).End(xlUp).Offset(-1).Row

For Each rng In [A2].Resize(LR)
    If Not IsError(Application.Match(rng, Sheets(2).Columns(1), 0)) Then
        rng = vbNullString
    End If
Next rng

Columns(1).SpecialCells(xlCellTypeBlanks).EntireRow.Delete

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,721
Messages
6,174,098
Members
452,542
Latest member
Bricklin

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