ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Omitting Duplicate values using a ComboBox or Data Validation (https://www.excelbanter.com/excel-discussion-misc-queries/204953-omitting-duplicate-values-using-combobox-data-validation.html)

PCLIVE

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

Regards,
Paul

--




[email protected]

Omitting Duplicate values using a ComboBox or Data Validation
 
On Oct 3, 8:17*pm, "PCLIVE" wrote:
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



All times are GMT +1. The time now is 06:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com