Remove Duplicates from the Array
Option Base 1
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Dim Rng As Range
Set Rng = Range("F2")
If Not Intersect(Target, Range("F2")) Is Nothing Then
'Clear the existing content
Range("F5:F" & Range("F5").End(xlDown).Row).ClearContents
Dim ColNumb As Integer
If Range("F2").Value = "Item" Then
ColNumb = 1
ElseIf Range("F2").Value = "Price" Then
ColNumb = 2
ElseIf Range("F2").Value = "Zone" Then
ColNumb = 3
End If
Dim LastRow As Integer
LastRow = Cells(Rows.Count, ColNumb).End(xlUp).Row
Dim Arry() As Variant
ReDim Arry(LastRow - 4)
Arry = Range(Cells(5, ColNumb), Cells(LastRow, ColNumb))
Dim UniqueArry() As Variant
ArrayNumb = 0
For r = 1 To UBound(Arry)
DataFound = ""
Datas = Arry(r, 1)
For Rs = 1 To r
If Datas = Arry(Rs, 1) And r <> 1 And Rs < r Then
DataFound = "Yes"
Exit For
End If
Next
If DataFound <> "Yes" Then
ArrayNumb = ArrayNumb + 1
ReDim Preserve UniqueArry(ArrayNumb)
UniqueArry(ArrayNumb) = Datas
End If
Next
For U = 1 To UBound(UniqueArry)
Cells(4 + U, 6).Value = UniqueArry(U)
Next
End If
Erase Arry
Erase UniqueArry
Application.EnableEvents = True
End Sub