I would like to create a structure for repeated operations by using Do While Loop. The DElDuplicates, which searches for and deletes duplicates rows in a database is a good example to explain the situation. Having sorted the database on a specific 'code' field, the entries in the code column are processed row-by row. If the values of the currentCell and nextCell are the same, the currentCell row is deleted.
I think my problem is caused by the reference objects. I don't know how to name it in my worksheet.
Capture.PNG![]()
Sub DelDuplicates() Dim currentCell, nextCell Range("database").Sort key1:=Range("code") ----------- error here? Set currentCell = Range("code") Do While Not IsEmpty(currentCell) Set nextCell = currentCell.Offset(1, 0) If nextCell.Value = currentCell.Value Then currentCell.EntireRow.Delete End If Set currentCell = nextCell Loop End Sub
Bookmarks