Remove duplicates

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,924
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have this code in Sheet1 to remove duplicates:

Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

    If Application.CountIf(Me.Columns(1), Target.Value) <> 1 Then
    
        Application.EnableEvents = False
        
        Application.Undo
        
        Application.EnableEvents = True
    
    End If
    
End Sub

If I type 1 into cell A1, nothing happens, as expected.

If I then type 1 into cell A2, the code reverses and cell A2 becomes blank, also as expected.

Suppose instead of the value 1 but I type the value 1@ into cell A1. Again nothing happens.

But if I now type 1@ into cell A2, the code DOES NOT reverse that value, even though it's already in cell A1.

Is there something special with @ symbols?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
in this case there is a thing is special about @ - it is normally recognised as a part of an email address.
Your code works, but Excel doesn't wait for anyone :)
The moment you type 1@ and press Enter Excel converts it to a hyperlink: mailto:1@
When you execute Application.Undo it actually undoes the conversion to Hyperlink.
The problem with Application.Undo is that it only works for one action. So if you execute it a second time it will undo the previous undo and you will end up with a 1@ hyperlink.
 
Upvote 0

Forum statistics

Threads
1,223,891
Messages
6,175,229
Members
452,621
Latest member
Laura_PinksBTHFT

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