Omitting Duplicate values using a ComboBox or Data Validation

P

PCLIVE

Is it possible to have a ComboBox or a Data Validation list that will omit
duplicate values in the given range?

Regards,
Paul

--
 
K

krishnakrKC

Is it possible to have a ComboBox or a Data Validation list that will omit
duplicate values in the given range?

Regards,
Paul

--

In a sheet module

Function UNIQUE(r As Range)
Dim v, a, z
a = r.Value
With CreateObject("scripting.dictionary")
.comparemode = vbTextCompare
For Each v In a
If Not IsEmpty(v) Then
If Not .exists(v) Then .Add v, Nothing
End If
Next
If .Count > 0 Then UNIQUE = .keys
End With
End Function
Private Sub Worksheet_Activate()
With Me.ComboBox1
.Clear
.List = Application.Transpose(UNIQUE(Range("A1", Range("a" &
Rows.Count).End(xlUp))))
End With
End Sub

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top