Hello All, I am quite new to vba and learning one by one. Kindly excuse me if this is a very elementary question and forgive me for my ignorance.
Basically I have a macro which adds names to Column A sorts it in ascending order and then removes duplicates. I am attaching the code below. Everything works fine except for removing duplicates.
Your help would be greatly appreciated . Thanks in advance
Basically I have a macro which adds names to Column A sorts it in ascending order and then removes duplicates. I am attaching the code below. Everything works fine except for removing duplicates.
Your help would be greatly appreciated . Thanks in advance
VBA Code:
Sub Button1_Click()
Application.ScreenUpdating = False
Dim lastrow As Long, name As Range
Set name = Worksheets("Names").Range("J7")
Worksheets("Names").Select
If name <> "" Then
name.Copy
lastrow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
Range("A" & lastrow + 1).Select
ActiveSheet.PasteSpecial xlPasteAllExceptBorders
End If
Worksheets("Names").Sort.SortFields.Clear
Range("A" & lastrow).Sort , Key1:=Range("A1"), order1:=xlAscending, Header:=xlYes
ActiveSheet.Range("A1", "A" & lastrow).RemoveDuplicates , Header:=xlYes
name.Select
Application.ScreenUpdating = True
End Sub