Results 1 to 7 of 7

Excel VBA - Naming Range - Has Duplicates. Consider only Unique Values and Name that Range

Threaded View

  1. #1
    Forum Contributor
    Join Date
    06-05-2013
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2016
    Posts
    110

    Excel VBA - Naming Range - Has Duplicates. Consider only Unique Values and Name that Range

    Dear all,

    I'm facing an issue in Naming a Range.

    Sample Data:
    Grades

    1
    1
    2
    2
    3
    3

    I would like to get the above values as:
    1
    2
    3

    Name the Range of Values (1,2,3) as "Grades".

    Please see the below code which will print the unique values(here, grades) in column D.

    Option Explicit
    Sub GetUniqueGrades()
    
        Sheets("Grades").Select
        Range("A1").Select
    
        Dim d As Object
        Dim c As Variant
        Dim i, lr As Long
        
        Set d = CreateObject("Scripting.Dictionary")
        
        lr = Cells(Rows.Count, 1).End(xlUp).Row
        
        c = Range("A2:A" & lr)
        
        For i = 1 To UBound(c, 1)
            d(c(i, 1)) = 1
        Next i
    
        Range("D2").Resize(d.Count) = Application.Transpose(d.keys)
        
    End Sub
    PFA for reference.

    I would like these unique values to be considered as a Range of Values and also Name that Range.

    Note: Code to do the needful without Printing the unique values in a separate column.

    Please let me know if this would be possible

    Thanks,
    Vinod Krishna

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro to find duplicates, concatenate Unique Values, then delete old duplicates
    By lesoies in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-17-2013, 04:32 PM
  2. Sum values from Range 1 of cooresponding unique values in range 2
    By dlamin130 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-14-2012, 07:46 PM
  3. Replies: 6
    Last Post: 03-31-2009, 11:17 AM
  4. Replies: 2
    Last Post: 01-12-2006, 09:35 AM
  5. Dynamic range naming in VB6.3 for Excel
    By Paul Chapman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-05-2005, 11:07 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