Excel Macro/VBA Keep row with first instance of ID, delete all other rows

cynamin82

New Member
Joined
Jan 28, 2021
Messages
2
Hello All,

I am a newbie on here. I have a report with duplicate ID's in column A, but with different data captured in subsequent columns (data through column BJ). The number of rows may vary and the data starts in row 4. I would like to create a macro that detects duplicate ID's, and if the ID is a duplicate it would keep the first instance from the top to the bottom with that ID and delete the additional rows with duplicates of the ID. I cannot figure out the best way to do this. Any suggestions? Thanks!
 

Some videos you may like

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

mrshl9898

Well-known Member
Joined
Feb 6, 2012
Messages
1,709
Are the headers in row 4? If not, change to Header:=xlNo

VBA Code:
Sub RemoveDupes()

Dim sht As Worksheet
Dim LastRow As Long

Set sht = ActiveSheet

LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row

    sht.Range("$A4:$BJ" & LastRow).RemoveDuplicates Columns:=1, Header:=xlYes

End Sub
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,127,611
Messages
5,625,829
Members
416,138
Latest member
Pizzaman22

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