Excel VBA to extract part of string and concatenate them with "," (Unique values only

  • Dear all,


    In the data available in attachment, i am trying to extract starting 3 letters of each cell value and add only UNIQUE values with ',' separator.


    I tried to find logic with below code but i know it fails.
    Can anyone please help me to correct it or provide fresh code to achieve the intent.
    Output required is as shown in the attachment.


    Many thanks.


    Just in order to get best possible solution, this querry is cross posted @
    http://www.excelforum.com/showthread.php?t=1146299&p=4425730#post4425730



  • Re: Excel VBA to extract part of string and concatenate them with "," (Unique values


    Here is one way:

  • Re: Excel VBA to extract part of string and concatenate them with "," (Unique values


    Thanks for your response..
    I want this value to be stored as a variable..I am upto the below code, but i am failing to pull UNIQUE values.
    Can anyone please help..?


  • Re: Excel VBA to extract part of string and concatenate them with "," (Unique values


    Just store it in a variable then instead of the sheet

  • Re: Excel VBA to extract part of string and concatenate them with "," (Unique values


    This will work IF your data are sorted before running

    Your logic is wrong because, among other things, you were comparing pc only with the previous value of pc1.

  • Re: Excel VBA to extract part of string and concatenate them with "," (Unique values


    Will this work for you?



  • Re: Excel VBA to extract part of string and concatenate them with "," (Unique values


    Hello Stephen,
    Now i realized by mistake...Thanks your code..:)
    And sorry for cross-posting..I am not among those who just put in their concern and let others work on it..
    I try to understand the logic and realize where i commit mistake..


    Your code still make "ALS" as duplicate entry....


    I think it still requires modification..Please help..

  • Re: Excel VBA to extract part of string and concatenate them with "," (Unique values


    sktneer..Yes your codes works perfectly..:) Thanks for your response..


    Can you please help me to correct previous code..?
    Is it possible to check if pc<>pcDiv1 instead of pc<>pc1..?


    Anyhow this thread is solved..:)


    Code
    pc <> pc1]Then
     pcDiv1 = pcDiv1 & "," & pc

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!