Clear cell content if found matching in another column

maheshr68

Board Regular
Joined
Sep 25, 2009
Messages
68
Greetings!!

Need to solve this puzzle, unsuccessfully googled..

Have data in columns A,B and C as -

country,region and city

India, Maharashtra,Thana
India,Madhya Pradesh,Gwalior
United Arab Emirates,Dubai,Dubai
India,India,India
Pakistan,Pakistan,Pakistan
United Arab Emirates,Abu Dhabi,Abu Dhabi
India,Delhi,Delhi
Spain,Madrid,Pozuelo De Alarcón
Spain,Madrid,Madrid
Spain,Madrid,Madrid
Spain,Madrid,Fuenlabrada

assuming the above entries start from row 2, cells to be cleared

a) in colB w.r.to colA
B5
B6
B11

b) in colC w.r.to colB
C4
C5
C6
C7
C8
C10

Unsuccessfully tried vlookup to filter the unwanted entries..

Best Regards,
Mahesh
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I don't see a consistent requirement in which cells you wish to clear.

If you want to clear from Column B any values that equal the corresponding cell in Column A, then why do you want to clear B11 (A11 = Spain, B11 = Madrid)?

If you want to clear from Column C any values that equal the corresponding cell in Column B, then why don't you want to clear C11 (B11 = Madrid, C11 = Madrid)?

That said, if I understand you correctly, then the easiest solution is to "clear" them with Conditional Formatting.

Select B2:C12 and in Conditional Formatting/Enter New Rule/Use a Formula, enter =B2=A2

Then, choose Format/Number/Custom/Type and enter ;;;

OK your way out and you should have what you want.
The values are still there, but they'll be invisible. Does that work for you?

If not, you can enter in D2: =IF(B2<>A2, B2, "") and copy it to D2:E12.

You can then hide B:C or Group and close them.
 
Upvote 0
Alternatively, if you want to use a macro to really get rid of the values, then, enter the following code into a module:

Code:
Sub clearDupes()
    Application.ScreenUpdating = False
 
    With Selection
        Dim i!, j!
 
        For j = .Columns.Count To 2 Step -1
            For i = 1 To .Rows.Count
                If .Cells(i, j) = .Cells(i, j - 1) Then .Cells(i, j).ClearContents
            Next i
        Next j
    End With
 
    Application.ScreenUpdating = True
End Sub

Then, select the entire table and run the macro.
 
Last edited:
Upvote 0
Greetings UniMord,

Thank You!!, this macro will help very much solve the puzzle.

Since there was no email notification on this particular thread & tied up with couple of other things too :)) , i was totally unaware of someone having posted a valuable reply.

Best Regards,
Mahesh
 
Upvote 0

Similar threads

Forum statistics

Threads
1,224,603
Messages
6,179,856
Members
452,948
Latest member
UsmanAli786

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