Data Validation List with Unique Values Only

tcustance

New Member
Joined
Sep 3, 2019
Messages
7
Hello all,

Is there a way to return unique values only in a data validation list that is frequently being refreshed?

Thanks,
Trent
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Is there a way to return unique values only in a data validation list that is frequently being refreshed?
Where is the list coming from?
If it is coming from somewhere on a worksheet, you can use Excel's built-in "Remove Duplicates" functionality to remove the duplicates.
Depending on how this list is being edited, you may even be able to automate that process with VBA.
 
Upvote 0
Where is the list coming from?
If it is coming from somewhere on a worksheet, you can use Excel's built-in "Remove Duplicates" functionality to remove the duplicates.
Depending on how this list is being edited, you may even be able to automate that process with VBA.

The list is generated through MS Query. I am using the list for sorting purposes, so I don't want to actually remove the duplicates from my data, i just want to be able to sort using my dropdown of unique results.

Thanks
 
Upvote 0
I am not sure I understand.
How exactly do you use a Data Validation list for sorting purposes?

Have you considered filtering/sorting the list right in the MS Query code, so the data comes across exactly as you need it?
 
Last edited:
Upvote 0
I am not sure I understand.
How exactly do you use a Data Validation list for sorting purposes?

Have you considered filtering/sorting the list right in the MS Query code, so the data comes across exactly as you need it?

I am using MS query to pull all of the data I want to be able to be sorted. I want to pull all of the data because i want to be able to sort it on the sheet (the other people using this sheet aren't familiar with sorting through the MS query window and the sorting will be frequently changed as well). I have another sheet with an summary of all of the data.(i.e. how many orders we have for a certain customer). When I use data validation on the cells, it has all of the duplicates.

Sorry if this is confusing.
 
Upvote 0
Can you make a copy of the data to another sheet where you remove all the duplicates, and use that?
 
Upvote 0
Supposing your data start from cell(A2) , cell (A1) is the Header
the cell C1 is the target for data validation
try this macro
Code:
Option Explicit


Sub Uniq_Data_Val()
Dim i%: i = 2
Dim arr
Dim rg As Object
Dim Last_ro%: Last_ro = Cells(Rows.Count, 1).End(3).Row
Set rg = CreateObject("System.Collections.Arraylist")
With rg
    Do Until i > Last_ro
        If Range("a" & i) <> vbNullString _
             And Not .Contains(Range("a" & i).Value) Then
            .Add Range("a" & i).Value
        End If
      i = i + 1
    Loop
  .Sort
  arr = .toarray
  arr = Join(arr, ",")
 End With
 
 With Range("c1").Validation
 .Delete
 .Add xlValidateList, Formula1:=arr
 End With
End Sub
ABC
1NameAlbert
2Sami
3John
4Goerge
5Albert
6
7Goerge
8Salim
9Ali
10
11Kamel

<tbody>
</tbody>
Sheet1
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,517
Messages
6,119,984
Members
448,935
Latest member
ijat

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top