Macro and VBA that deletes the oldest records, if they are the same value

Asked

Viewed 23 times

0

Talk, guys, I’m new here and I’m desperate for some help.

I need you to delete the oldest records from a list of multiple trips, keeping only the latest of them. The print below makes it clearer.

inserir a descrição da imagem aqui

In this case I would need those of 09/21 and 09/23 to be erased, leaving only those of 09/26. The problem is that it has repeats on the boards and that, if they are the latest, they need to be maintained.

Help a desperate college boy :(

1 answer

0

Sub removerAntigo()

Dim UltimaLinha As Long
UltimaLinha = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row

Dim i As Long
For i = 2 To UltimaLinha

If Cells(i, 1).Value = "" Then Exit Sub

If Cells(i, 3) = Cells(i + 1, 3) Then

    If Cells(i, 1) <= Cells(i + 1, 1) Then
    
    Rows(i).Delete
    If i = 2 Then i = 1
    
    End If

End If

Next i

End Sub

I ended up doing a scope here but I haven’t succeeded yet, my macro deletes values, but it doesn’t keep the plates equal with the same date, as shown in the question image. Also, it’s not just a plaque, this was an example, I didn’t bother to mention it before. In short: I will paste a report of a certain date range (1 week for example) and want to make sure that I will not have duplicity at the time I use it to analyze the data. Being a transport report, where I can have more than one knowledge per board (as is the case of the day 26/09 in the image), and different boards in the report, always keeping the latest.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.