Deleting Rows with duplicate unique key entries

dazfoz

Board Regular
Joined
Dec 21, 2007
Messages
205
Hi all,

Hope you can help, I have a second hand spreadhsheet, that I have kind of butchered, and managed to get working, but i'm having a bit of a problem with one piece of the code. The spreadsheet can search and return a line of data based on the unique key (in column A), and then this data can be amended and saved, but when it is saving, it should delete the first line of data, and just leave the newly saved data, but at the moment it is saving the data, but not deleting the original line. It will always be the newest line of data that is to be deleted.

This is the code that is currently in the spreadsheet, any help would be appreciated.

Daz

Code:
Application.ScreenUpdating = False
Sheets("Data").Select
Const lookup_column As String = "a"
Dim i As Long
Dim LastRow As Long
Dim LastRows As Long
Dim cell As Range
Dim sh As Worksheet

    With ActiveSheet
        
        LastRow = .Cells(.Rows.Count, lookup_column).End(xlUp).Row
        For i = LastRow - 1 To 2 Step -1
        
            If Application.CountIf(.Cells(i, lookup_column).Resize(LastRow - i + 1), .Cells(i, lookup_column)) > 1 Then
            
                .Rows(i).Delete
            End If
        Next i
               LastRows = WorksheetFunction.CountA(Range("a:a"))
        Worksheets("INPUT PAGE").Range("E144").Value = LastRows
    End With
'
ActiveWorkbook.Save
    Sheets("Front Page").Select
    Range("a75").Select
    Application.ScreenUpdating = True
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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