-4

Can somebody help me to create an excel vba code below

For each cell in column 2 "Sequence", I want to split an string by a comma "," and store unique string in an array and populate the result in column 4!

Sorry, I can't attach a photo, there is an error, below is the details.

column 2
row 1 - R001,R002,R003,R004
row 2 - R003,R004,R005,R006
row 3 - R006,R009,R010,R011

column 4 (result should be)
row 1 - R001
row 2 - R002
row 3 - R003
row 4 - R004
row 5 - R005
row 6 - R006
row 7 - R009
row 8 - R010
row 9 - R011
Ron Rosenfeld
  • 53,870
  • 7
  • 28
  • 60
J1903
  • 7
  • 1
  • 2
    Show us what you have tried, and where you have run into problems. It might help to read the HELP pages for information as to [How to Ask a Good Question](http://stackoverflow.com/help/how-to-ask), and [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – Ron Rosenfeld Oct 31 '19 at 10:21
  • First, your "attached photo" seems to be missing. Secondly, can you show us what you have tried to accomplish this, and where you have gotten stuck? If you haven't made an attempt to solve your own problem, [you will likely get downvoted](https://idownvotedbecau.se/noattempt/) and might not receive an answer. – Plutian Oct 31 '19 at 10:21
  • Sorry, I cant attach a photo, I dont know why. I edited the description. – J1903 Oct 31 '19 at 10:49

2 Answers2

2

For fun, I wanted to see if this could be done with worksheet formulas.

If you happen to have O365 with the FILTERXML and TEXTJOIN functions, you can use the formula below:

=IFERROR(INDEX(FILTERXML("<t><s>" & SUBSTITUTE(TEXTJOIN(",",,$A$1:$A$3),",","</s><s>") & "</s></t>","//s[not(. = preceding::*)]"),ROWS($1:1)),"")

Algorithm:

  • Join the relevant cells with a comma delimiter
  • Create an XML from the text, with the commas separated the nodes.
  • Use the xPath argument to only return a node if it is not preceded by an identical node

enter image description here

enter image description here

Ron Rosenfeld
  • 53,870
  • 7
  • 28
  • 60
-1

Check out following links

Split function

Removing duplicates