Deleting Duplicates

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,047
Office Version
  1. 2016
Platform
  1. Windows
I am using this to delete duplicates from column B, it work well. only has one problem. Some of the cells have a hyphen in them. I need the code to disregard these and NOT delete them as a duplicate. Therefore any Cells in Sheet3 Column B that have a hyphen are Not to be regarded as duplicates and therefore they are not deleted.

VBA Code:
'''delete duplicates in Sheet3 column B
Dim Cl As Range, Rng As Range
   With CreateObject("scripting.dictionary")
      For Each Cl In Sheets("Sheet3").Range("B2", Sheets("Sheet3").Range("B" & Rows.Count).End(xlUp))
         If Cl <> "" Then
            If Not .Exists(Cl.Value) Then
               .Add Cl.Value, Nothing
            Else
               If Rng Is Nothing Then Set Rng = Cl Else Set Rng = Union(Rng, Cl)
            End If
         End If
      Next Cl
   End With
   If Not Rng Is Nothing Then Rng.EntireRow.Delete
 

Some videos you may like

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,238
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
         If Cl <> "" And InStr(1, Cl.Value, "-") = 0 Then
 
Solution

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,047
Office Version
  1. 2016
Platform
  1. Windows
Cheers Fluff, Super Work
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,238
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,126,965
Messages
5,621,871
Members
415,862
Latest member
nascaline

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
Top