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!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
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
 
Upvote 0
Solution

Forum statistics

Threads
1,214,622
Messages
6,120,580
Members
448,972
Latest member
Shantanu2024

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