Posted By

fugue on 10/24/08


Tagged

excel vba


Versions (?)

Delete Duplicates


 / Published in: Visual Basic
 

Walk a column and delete duplicate cells (assumes the list to have been sorted already).

  1. Sub DeleteDuplicates()
  2. '
  3. ' DeleteDuplicates Macro
  4. ' Delete duplicate values in a column
  5. '
  6.  
  7. '
  8.  
  9. Dim previousVar As String
  10.  
  11. Range("A1").Select
  12. Do Until Selection.Value = ""
  13. If Selection.Value = previousVar Then
  14. 'Selection.Value = ""
  15. Selection.Delete Shift:=xlUp
  16. Else
  17. Selection.Offset(1, 0).Select
  18. previousVar = Selection.Value
  19. End If
  20. 'Selection.Offset(1, 0).Select
  21. Loop
  22. Range("A1").Select
  23.  
  24. End Sub

Report this snippet  

You need to login to post a comment.