Podcast 1375 - better concatenate

vaibhav106

New Member
Joined
Jan 28, 2009
Messages
40
In recent podcast no 1375 nice simple code is shown to join the range of text.
but..
when the range have few blank cells then the separator repeats unnecessarily. How we can ask the code to skip the blank cell while joining the range?
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
I use the following function to concatenate ranges:

Code:
Function Concatenate_Range(myrange As Range, Optional myDelimiter As String)
Dim cell As Range

Application.Volatile

For Each cell In myrange
    If Len(cell.Value) > 0 Then
        Concatenate_Range = Concatenate_Range & cell & myDelimiter
    Else: Concatenate_Range = Concatenate_Range
    End If
Next cell

If Len(myDelimiter) > 0 Then Concatenate_Range = Left(Concatenate_Range, Len(Concatenate_Range) - Len(myDelimiter))

End Function
 
Upvote 0
thanks for such lightning reply..

I have used your idea in the existing code & updated that code as under:-


Function Join(RangeToJoin, Separator)
Join = ""
For Each cell In RangeToJoin
If Len(cell.Value) > 0 Then
Join = Join & cell.Value & Separator
Else: Join = Join
End If
Next cell
If Len(Join) > 0 Then
Join = Left(Join, Len(Join) - Len(Separator))
End If

End Function
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,787
Members
452,942
Latest member
VijayNewtoExcel

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