Hello,
I have searched and tried a lot but can't find the right answer.
Headers in row 7.
Data range= ("A8": last cell in column "Q")
Column "A"= Names
Column "B"= Dates
Code deletes rows with: duplicates in column"A" and oldest dates in column "B".
Code is working fine but it deletes the entire row when it finds a duplicate in column "A".
Question is: How to only delete cells, column "A:Q" and move up data, so there are no rows with empty cells in "Data range"?
Any help is much appreciated.
Thanks in advance!
I have searched and tried a lot but can't find the right answer.
Headers in row 7.
Data range= ("A8": last cell in column "Q")
Column "A"= Names
Column "B"= Dates
Code deletes rows with: duplicates in column"A" and oldest dates in column "B".
Code is working fine but it deletes the entire row when it finds a duplicate in column "A".
Question is: How to only delete cells, column "A:Q" and move up data, so there are no rows with empty cells in "Data range"?
Code:
Sub Macro2()
Dim i As Long
Dim sht As Worksheet
Dim lastRow As Long
Dim StartCell As Range
Set sht = Worksheets("Sheet1")
Set StartCell = Range("A8")
lastRow = sht.Cells(sht.Rows.Count, StartCell.Column).End(xlUp).Row
sht.Range(StartCell, sht.Cells(lastRow, "Q")).Sort Key1:=Range("A8"), Order1:=xlAscending, Key2:=Range("B8") _
, Order2:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom
For i = Range("A65000").End(xlUp).Row To 8 Step -1
If Cells(i, 1) = Cells(i + 1, 1) Then Rows(i).EntireRow.Delete
Next i
End Sub
Thanks in advance!
