Some options. The first is your code with the Named Range added; the others are variations. The second avoids cell selection and tidies up a bit. And the third one uses an Advanced Filter rather than using a Dictionary and looping through the cells.
Option Explicit
Sub GetUniqueGrades_TMS1()
Sheets("GradesNames").Select
Range("A1").Select
Dim d As Object
Dim c As Variant
Dim i, lr As Long
Set d = CreateObject("Scripting.Dictionary")
lr = Cells(Rows.Count, 1).End(xlUp).Row
c = Range("A2:A" & lr)
For i = 1 To UBound(c, 1)
d(c(i, 1)) = 1
Next i
' put the named range in column D ...
With Range("D2").Resize(d.Count)
.Value = Application.Transpose(d.keys)
.Name = "nrGrades1"
End With
End Sub
Sub GetUniqueGrades_TMS2()
Dim d As Object
Dim c As Variant
Dim i, lr As Long
Set d = CreateObject("Scripting.Dictionary")
With Sheets("GradesNames")
lr = .Cells(.Rows.Count, 1).End(xlUp).Row
c = .Range("A2:A" & lr)
For i = 1 To UBound(c, 1)
d(c(i, 1)) = 1
Next i
' put the named range in column E ...
With .Range("E2").Resize(d.Count)
.Value = Application.Transpose(d.keys)
.Name = "nrGrades2"
End With
End With
Set d = Nothing
Erase c
End Sub
Sub GetUniqueGrades_TMS3()
Dim lr As Long
With Sheets("GradesNames")
lr = .Cells(.Rows.Count, 1).End(xlUp).Row
' put the named range in column F ...
.Range("A1:A" & lr).AdvancedFilter _
Action:=xlFilterCopy, _
CopyToRange:=Cells(1, 6), _
Unique:=True
lr = .Cells(.Rows.Count, 6).End(xlUp).Row
.Range(.Cells(2, 6), .Cells(lr, 6)).Name = "nrGrades3"
End With
End Sub
Regards, TMS
Bookmarks