I'm looking to compare two strings within two adjacent cells. All values separated by a comma. Returning the matched values separated by a comma.
Values are sometimes repeated more than once, and can be in different parts of the string. The largest string length in my list is 6264.
e.g.
Cell X2 = 219728401, 219728401, 219729021, 219734381, 219735301, 219739921
Cell Y2 = 229184121, 219728401, 219729021, 219734333, 216235302, 219735301
Result/Output = 219728401, 219729021, 219735301
The cells I would like to apply this to is not limited to only X2 and Y2, it would be columns X and Y, with output into column Z (or a column I can specify).
I appreciate any help with this, as my VBA knowledge is limited in Excel.
Thank you.
Here's another version that uses a Dictionary object to assess matches.
It also uses arrays to speed up the processing -- useful with large data sets.
Be sure to set a reference as noted in the comments of the code, but if you are going to be distributing this code, you may prefer to use late-binding.
One assumption is that all of your values are numeric. If some include text, you may (or may not) want to change the dictionary comparemode to Text.
If you now select a range of rows and run the macro - it will fill in Z column for each row selected based on X and Y column inputs.
Note if you have 2,1,2 and 2,5,2 and want 2,2 then remove the if Not Found part and add each time.