Consulting

Results 1 to 5 of 5

Thread: Unique names

  1. #1

    Unique names

    Good afternoon,

    I need to fill cell D2 with unique values ​​in RANGE (A2: A20), it can be VBA or formula.



    Thank you for your help


    RomuloRDM
    Attached Files Attached Files

  2. #2
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    613
    Location
    .
    Paste this formula in D2 :
    =INDEX($A$2:$A$20,RANDBETWEEN(1,COUNTA($A$2:$A$20)),1)
    You can update the random selection by pressing F9
    Attached Files Attached Files

  3. #3
    Good afternoon,


    I think I did not express clearly, what I need and that in cell D2 the names appear comma-separated.
    Example:
    Antonio, Pedro, Joaquim, Geraldo, Jose ..... and do not leave repeated.


    Thanks and sorry..

  4. #4
    VBAX Expert Leith Ross's Avatar
    Joined
    Oct 2012
    Location
    San Francisco, California
    Posts
    552
    Location
    Hello Romulo,

    This macro is a User Defined Function. It works like a Formula. The code below has been added to the attached workbook.

    Public Dict As Object
    
    
    Function GetUniqueNames(SrcRng As Range) As String
    
    
        Dim Data    As Variant
        Dim Key     As Variant
        
            Application.Volatile
            
            If Dict Is Nothing Then
                Set Dict = CreateObject("Scripting.Dictionary")
                Dict.CompareMode = vbTextCompare
            End If
                
                Dict.RemoveAll
                
                Data = SrcRng.Value
                
                For Each Key In Data
                    Key = Trim(Key)
                    If Key <> "" Then
                        If Not Dict.Exists(Key) Then
                            Dict.Add Key, Key
                        End If
                    End If
                Next Key
                
            GetUniqueNames = Join(Dict.Items, ",")
            
    End Function
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    "1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG"

  5. #5
    Good evening,


    Many thanks to all, Leith Ross was very good, thanks for the support.


    Att.

Posting Permissions

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