Delete duplicates cells

MayHmne

New Member
Joined
Sep 3, 2020
Messages
26
Office Version
  1. 2019
Platform
  1. Windows
I have tried the below macro and it is working but when applying it on a larger range of data (specifically 17137 rows) a considerable amount of data are deleted not just the duplicates

RemoveDupes add blank
Sub RemoveDupes()
Dim X As Long
For X = 1 To Range("A" & Rows.Count).End(xlUp).Row
If Application.WorksheetFunction.CountIf(Range("A1:A" & X), Range("A" & X).Text) > 1 Then Rows(X).ClearContents
Next
End Sub

so, any other codes that solve this issue?
Untitled.png
 
I don't know what to advise. The macro functions here.

????
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
.
Here is a different approach :

Code:
Option Explicit

Sub DeleteDups()
    
    Dim x               As Long
    Dim LastRow         As Long
    Dim Cells           As Range
    Application.ScreenUpdating = False
    With ActiveSheet
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        LastRow = LastRow
    End With
 
    For x = LastRow To 1 Step -1
        If Application.WorksheetFunction.CountIf(Range("A1:A" & x), Range("A" & x).Text) > 1 Then
            Range("A" & x).EntireRow.Delete
        End If
    Next x
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
The macro is designed to check column A : Range("A1")

If you are checking a different column for the duplicates, change the A to the other column letter.
The macro is designed to check column A : Range("A1")

If you are checking a different column for the duplicates, change the A to the other column letter.

unfortunately, another error appears
Untitled.png
 
Upvote 0
I
.
Here is a different approach :

Code:
Option Explicit

Sub DeleteDups()
   
    Dim x               As Long
    Dim LastRow         As Long
    Dim Cells           As Range
    Application.ScreenUpdating = False
    With ActiveSheet
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        LastRow = LastRow
    End With

    For x = LastRow To 1 Step -1
        If Application.WorksheetFunction.CountIf(Range("A1:A" & x), Range("A" & x).Text) > 1 Then
            Range("A" & x).EntireRow.Delete
        End If
    Next x
    Application.ScreenUpdating = True
   
End Sub
This one works, but it doesn't enter empty rows instead for cells that have been deleted
 
Upvote 0
VBA Code:
Option Explicit

Sub DeleteDups()
    
    Dim x               As Long
    Dim LastRow         As Long
    Dim Cells           As Range
    
    Dim lRow            As Variant
    
    Application.ScreenUpdating = False
    With ActiveSheet
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        LastRow = LastRow
    End With
 
    For x = LastRow To 1 Step -1
        If Application.WorksheetFunction.CountIf(Range("A1:A" & x), Range("A" & x).Text) > 1 Then
            Range("A" & x).EntireRow.Delete
        End If
    Next x
    
    With ActiveSheet
            lRow = .Range("A" & .Rows.Count).End(xlUp).Row
            .Range("A1:A" & lRow).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    End With
        
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,834
Messages
6,181,243
Members
453,026
Latest member
cknader

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