VBA: Join function help

h711

Board Regular
Joined
Jun 23, 2008
Messages
164
I have little problem with the join function
Join(soucearray, delimiter)

Let's say I have an array of names, but some of the names are null. So I only need the join function to join those are not null. For example:

Name1=
Name2
Name3="Tom"
Name4
Name5="Jack"

When I use

Join(Array(name1, name2, name3, name4, name5), ",")

I need the result to be: Tom,Jack
not: ,,Tom,,Jack

I don't know which name is null and which may have value in it, so I need to include the full list of the name there.

Thanks for the help!
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Thanks, but this replace with remove all the ",". I still need the "," between the names, such as Tom,Jack

I only need to remove those extra "," caused by null string.
 
Upvote 0
Unlike the code above, this has only one space between the first and second double quotes
Code:
Replace(WorksheetFunction.Trim(Join(myNames)), " ", ",")
 
Upvote 0
I think Mike just mistyped that. The replace is of two separators with one.

Code:
replace$(join$(myNames, ",,", ","))
 
Upvote 0
Thanks guys. But it still does not work right.

Let's say only Name5 has value. After these statements the result is still: ,Jack
 
Upvote 0
Code:
Join(Split(WorksheetFunction.Trim(Join(Array(name1, name2, name3, name4, name5)))),",")
 
Upvote 0

Forum statistics

Threads
1,214,387
Messages
6,119,225
Members
448,877
Latest member
gb24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top