I have just finished rebuilding my join functions to implement recursive behaviour (where the function calls itself), an idea taken from my recent build of a function that joins Excel ranges together. These functions mimic the behaviour of the Join() function which joins an array of strings together with a delimiter (e.g. a comma for CSV).

Simple one first...

JoinStr
Please Login or Register  to view this content.
Hopefully you can see how this behaves. It takes each item you input, checks it is a string, checks it's not empty, then adds it to the end of output with the delimiter. At the end it removes the delimiter at the beginning of the output string. So...
Please Login or Register  to view this content.
would finally output "C:\TEMP\myfiles". The first pass would give "\C:" because JoinStr = "" initially ... ... "" & "\" & "C:" = "\C:" which is why we remove the first delimiter at the end.



JoinCol and JoinArr work on the same principles, except they check the input for more properties than just being a string. If the input is not a string, and if IncludeSubLevels = True, then they check for arrays and collections which are then in turn checked for strings, or collections, or arrays, and so on and so on.

JoinCol
Please Login or Register  to view this content.
JoinArr
Please Login or Register  to view this content.
To test this you can step through the following sub:
Please Login or Register  to view this content.


Last but not least, a similar Excel-specific function that 'joins' ranges together into a single range using Application.Union. This is the equivalent of holding CTRL down when selecting different ranges. These ranges can be in pretty much any format, including collections, arrays, variables, etc.
(note that you need the AddRng procedure at the bottom, too)

JoinRng
Please Login or Register  to view this content.
To test this you can step through the following sub:
Please Login or Register  to view this content.
As always I have left the author information in because I'm too lazy to remove it, and the notes are helpful.
Feel free to remove / edit / play with any part of my code or comments to your heart's content!