Delete duplicates BUT ignore Blank Cells.

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,064
Office Version
  1. 2016
Platform
  1. Windows
I want to delete any rows that have duplicates in Sheet3 column B to the last row with data in it starting from row 2.

However it needs to ignore any blank cells in column B and NOT delete them. As I tried excel's delete duplicates and it was taking the blank cells and also deleting them. I tried to write a vba code, but it would only look for duplicates until it reached the first blank cell. So if column B had data Row 1 to 100 and cell B30 was empty my code only check upto B2 to B30. I need one that would do the lot.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Do you want to delete all dupes, or do you want to leave one instance of each?
 
Upvote 0
Hi Fluff
leave one instance of each. I need at least one record. However all rows that have a Blank/Empty Cell in Sheet3 column B are NOT deleted.
 
Upvote 0
Ok, how about
VBA Code:
Sub Sharid()
   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
End Sub
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,954
Messages
6,122,461
Members
449,085
Latest member
ExcelError

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