VBA to delete duplicate and blank rows

slora00

New Member
Joined
Sep 8, 2022
Messages
25
Office Version
  1. 2016
Platform
  1. Windows
Hello community, I hope y'all doing fine. I need some help with the following task:

I have a 13k rows file, but with at least 2000 duplicates, and I need to delete them but considering column N.

I need a VBA code that deletes all duplicates on column A that are empty on column N. I tried the following:

VBA Code:
Dim ColorRng As Range
Dim ColorCell As Range
Dim hoja As Worksheet
Set hoja = ActiveSheet
Set ColorRng = hoja.Range("A2:AB" & Cells(Rows.Count, "A").End(xlUp).Row)

For Each ColorCell In ColorRng
    If WorksheetFunction.CountIf(ColorRng, ColorCell.Value) > 1 And IsEmpty(Range("N2:N" & Cells(Rows.Count, "A").End(xlUp).Row)) = True Then
        ColorCell.EntireRow.Delete
            
    Else
    ColorCell.Interior.ColorIndex = xlNone
        
    End If
Next

But the "IsEmpty" part seems to be not working.

Feel free to either correct my code, or write a new one instead.

Thank you in advance!
 
Hello Kevin, just tested the code and it works, but there's an issue. When it deletes the rows, the macro shifts up some rows and takes away the table headers. If it's not much to ask, is there any way to fix this?
"Table headers"? I'm afraid I have no idea what your data looks like now. Before I can assist any further, I'll need to see your actual data layout using the XL2BB add in. Please don't describe what it looks like - I need to see it for myself.
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,216,101
Messages
6,128,845
Members
449,471
Latest member
lachbee

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