I am trying to create a VBA script to do the above but the problem is even with screen updating turned off it takes a long time to run. Here is my code:
As you can see the code requires you to select the topmost cell of the list. It would be handier if I can just generate the list of unique values by (a) clicking anywhere in the list and (b) being able to post the original list anywhere in the worksheet so that whole rows containing other data are not deleted - I only want to delete the cells containing duplicates. All this obviously in code that runs much more quickly. Can anyone advise?
EDIT: this assumes the list is in alphabetical order, so again I just want to be able to dump the list anywhere in the worksheet, and make Excel do the sorting and deleting of duplicates without affecting the rest of the data if there is any. Thanks!
Code:
Sub ListOfUniqueValues()
Application.ScreenUpdating = False
Dim r As Integer, c As Integer
r = ActiveCell.Row + 1
c = ActiveCell.Column
Do Until Cells(r, c) = ""
If Cells(r, c) = Cells(r - 1, c) Then
Rows(r).Delete
Else: r = r + 1
End If
Loop
Application.ScreenUpdating = True
End Sub
As you can see the code requires you to select the topmost cell of the list. It would be handier if I can just generate the list of unique values by (a) clicking anywhere in the list and (b) being able to post the original list anywhere in the worksheet so that whole rows containing other data are not deleted - I only want to delete the cells containing duplicates. All this obviously in code that runs much more quickly. Can anyone advise?
EDIT: this assumes the list is in alphabetical order, so again I just want to be able to dump the list anywhere in the worksheet, and make Excel do the sorting and deleting of duplicates without affecting the rest of the data if there is any. Thanks!
Last edited: