+ Reply to Thread
Results 1 to 7 of 7

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

  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.

    Please Login or Register  to view this content.
    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

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,366

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

    Some options. The first is your code with the Named Range added; the others are variations. The second avoids cell selection and tidies up a bit. And the third one uses an Advanced Filter rather than using a Dictionary and looping through the cells.

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,366

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

    Thanks for the rep


    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

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

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

    Dear TMS,

    Well, I asked you one solution and you gave me three You simply exceed ones expectations

    One small request:
    How about modifying the above code in such a way that you don't print it in any of the columns?

    Idea for possible Solution:
    * Consider the Range of Values from A2 to Last Cell (Row wise).
    * Store all the unique values into a Array, say UniqueGrades.
    * Consider that Array as a Range
    * Name that Range as "GradesList"

    Please let me know if this would be possible

    Regards,
    Vinod Krishna

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,366

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

    Hi Vinod.

    Yes, I tried that but I couldn't get it to work properly. Well, I could create a Named Range that refers to an array and the array contains the grades, but I couldn't use it in Data Validation as I could with the others.

    See the attached updated workbook. See if you can get it to do what you want.

    Regards, TMS

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

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

    Dear TMS,

    Thank you for trying your level best.

    I guess its one of the drawbacks of Data Validation.

    I will continue to use the above logic.

    Will update on this post if I get to know of any Alternatives.

    Please let us all know if you get to know of any Alternatives.

    Thanks,
    Vinod Krishna

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,366

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

    I think the short, but sad, answer is that it cannot be done.

+ 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. [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. [SOLVED] Count unique values among duplicates in a subtotal range
    By jcpotwor in forum Excel General
    Replies: 2
    Last Post: 01-12-2006, 09:35 AM
  5. [SOLVED] 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