Clear duplicates between two columns

Pcwork2006

New Member
Joined
Jul 17, 2019
Messages
12
Good Days,
Please advise a vba code to process the duplicates values clean task,

If word/text in Cell A1 is equal to Cell B2 ,then Cell B2.clearcontents

......

If word/text in Cell A65536 is equal to Cell B65536, then Cell B65536.clearcontents

Else, no change

Thank you very much!
 
Last edited:
The @ is just a place holder & is replaced by .Address by the Replace function, so it basically becomes
Code:
Evaluate("if(" & .Address & "=" & .Offset(, -1).Address & ",""""," & .Address & ")")

Thank you.

I was confused with the address thing .

If the the cell in column B is empty the result is 0 instead of blank.

How would you amend your code to result in empty cells instead of 0s ?

I used the Text function but it fails with cells in column B that contain numbers.
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I like using simple Vba coding which I understand and hopefully others will to. But I'm sure other ways of coding things may be a few seconds faster.
My code worked for me which was in post 2

I agree with you but ,in my humble opinion, the important thing is to always learn new things whenever the opportunity arises.

Regards.
 
Upvote 0
Like
Code:
Sub Pcwork2006()
   With Range("B1", Range("B" & Rows.Count).End(xlUp))
      .Value = Evaluate(Replace("if(@=" & .Offset(, -1).Address & ","""",if(@="""","""",@))", "@", .Address))
   End With
End Sub
 
Upvote 0
Like
Code:
Sub Pcwork2006()
   With Range("B1", Range("B" & Rows.Count).End(xlUp))
      .Value = Evaluate(Replace("if(@=" & .Offset(, -1).Address & ","""",if(@="""","""",@))", "@", .Address))
   End With
End Sub

Cool!

I'll experiment further with similar examples.

Thank you.
 
Upvote 0
Try this:
Code:
Sub Clear_Me()
'Modified 8/26/2019 2:49:54 AM  EDT
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To Lastrow
    If Cells(i, 1).Value = Cells(i, 2).Value Then Cells(i, 2).Value = ""
Next
Application.ScreenUpdating = True
End Sub
Thank you,buddy.
This code solve my needs perfectly!
 
Upvote 0
Like
Code:
Sub Pcwork2006()
   With Range("B1", Range("B" & Rows.Count).End(xlUp))
      .Value = Evaluate(Replace("if(@=" & .Offset(, -1).Address & ","""",if(@="""","""",@))", "@", .Address))
   End With
End Sub

Thank you for your answer.
However I got #value result in all Column B
 
Upvote 0
Not quite sure why you would get that & I cannot replicate it.
Have you made any changes to the code?
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,988
Messages
6,128,146
Members
449,427
Latest member
jahaynes

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