I used eksortso's answer from vba: get unique values from array to get unique values from an array
Sub Trial()
Dim myArray() As Variant
Dim i As Long
Dim d As Object
myArray() = Array("Banana", "Apple", "Orange", "Tomato", "Apple", "Lemon", "Lime", "Lime", "Apple")
Set d = CreateObject("Scripting.Dictionary")
For i = LBound(myArray) To UBound(myArray)
d(myArray(i)) = 1
Next i
End Sub
This works perfectly but when I try to apply this to a range read off a worksheet, it gives me an error - Run-time error '9': Subscript out of range
Sub Clients()
Dim Sht As Worksheet
Dim LastRow As Long
Dim StartCell As Range
Dim ClientType As Variant
Dim UniqueType As Object
Dim i As Long
Set Sht = Worksheets("ALL CLIENTS")
Set StartCell = Range("F6")
'Find Last Row
LastRow = Sht.Cells(Sht.Rows.Count, StartCell.Column).End(xlUp).Row
'Read Client Type Column
ClientType = Sht.Range(StartCell, Sht.Cells(LastRow, StartCell.Column))
Set UniqueType = CreateObject("Scripting.Dictionary")
For i = (LBound(ClientType) - 1) To UBound(ClientType)
UniqueType(ClientType(i)) = 1
Next i
End Sub
Is this happening because myArray
is starting at subscript 0
while ClientType
is starting at 1
? How do I fix this?