Hello,
I have this code which should read all rows that begin with the word ACCOUNT#: which is followed by numbers like this: 1-026-31-00000-3342. The whole this looks like this ACCOUNT#: 1-026-31-00000-3342. If the code reads some row and there is another row identical to the row read in the beginning then the second row needs to get deleted.
Is it possible? This is what I have making so far but it doesn't work because the match function doesn't read that value.
I have this code which should read all rows that begin with the word ACCOUNT#: which is followed by numbers like this: 1-026-31-00000-3342. The whole this looks like this ACCOUNT#: 1-026-31-00000-3342. If the code reads some row and there is another row identical to the row read in the beginning then the second row needs to get deleted.
Is it possible? This is what I have making so far but it doesn't work because the match function doesn't read that value.
Code:
Sub SECOND_MACRO_Delete_DuplicateAccount()
Dim ws As Worksheet, row1 As Long, row2 As Long, rng As Long, n As Long, nlast As Long, rw As Range
Set rw = ActiveWorkbook.ActiveSheet.UsedRange.Rows
nlast = rw.Count
For Each ws In Sheets
For r = 1 To ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
If ws.Cells(r, "A") Like "*ACCOUNT*" Then
row1 = WorksheetFunction.Match(ws.Cells(r, "A").Value, ws.Columns(1), 0)
row2 = WorksheetFunction.Match(ws.Cells(r, "A").Value, ws.Columns(1), 0)
If ws.Range("A" & row1).Value = ws.Range("A" & row2).Value Then
ws.Rows(row2).Delete
End If
End If
Next ws
End Sub
Last edited: