+ Reply to Thread
Results 1 to 4 of 4

Create validation list of distinct values

Hybrid View

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Create validation list of distinct values

    Hello everybody
    I have three columns A - B - C with values ..
    I want in Range("E1") to create validation list of distinct values of the three columns using vba ??

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Create validation list of distinct values

    I tried this code
    Sub Unique()
        Dim r As Range, cel As Range, cell As Range
        Dim d, a
        Dim LR As Long, LastRow As Long, X As Long, Y As Long
        LR = Range("A" & Rows.Count).End(xlUp).Row
        Set r = Range("A1:C" & LR)
        
        On Error Resume Next
        
        Set d = CreateObject("Scripting.Dictionary")
        For Each cel In r
            If cel <> 0 Then d.Add CStr(cel), CStr(cel)
        Next
        a = d.items
            
        With Range("E1").Validation
            .Delete
            .Add Type:=xlValidateList, Formula1:=Application.Transpose(a)
        End With
    End Sub
    But It doesn't work for me .. I don't know why?

  3. #3
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Create validation list of distinct values

    Try this one..

    Sub Unique()
    Dim DEB As Range
        Set DEB = Range("a1:c" & Range("A" & Rows.Count).End(xlUp).Row)
        
        For Each cel In DEB
            If InStr(RAJ & ",", "," & cel & ",") = 0 Then RAJ = RAJ & "," & cel
        Next cel
        
        With Range("e1").Validation
            .Delete
            .Add xlValidateList, 1, 1, Mid(RAJ, 2)
        End With
    End Sub
    Regards!
    =DEC2HEX(3563)

    If you like someone's answer, click the star to give them a reputation point for that answer...

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Create validation list of distinct values

    Thank you very much Mr. Debraj Roy
    You are very helpful

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. howto select distinct values from list
    By chris in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 06-05-2015, 12:16 AM
  2. Create a Distinct Unique list for 2 Columns
    By boldcode in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-06-2014, 05:10 PM
  3. [SOLVED] Create a distinct list based on other criteria
    By tomtheappraiser in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-29-2014, 12:59 PM
  4. [SOLVED] Distinct List from Column of Values
    By dianaschar in forum Excel General
    Replies: 4
    Last Post: 03-26-2013, 11:39 AM
  5. [SOLVED] Data Validation Returning only distinct values from a list
    By JI in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-28-2006, 06:45 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1