Join range of cells into a single cell separated by vertical bar.

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,362
Office Version
  1. 2010
Using Excel 2010

Hello,

I want to join multiple cells C:G columns each row range, into single column “H” separated by vertical bar (having 1 space after and before the vertical bar)

Note: I want a formula or a macro which can be used in Excel 2000 also.

Here is an example sheet with expected results…

Odds.xls
ABCDEFGHI
1
2
3
4
5n1n2n3n4n5Join
6
77137 | 13
81919
977
101515
11
123233 | 23
13
14
1511517251 | 15 | 17 | 25
1657215 | 7 | 21
17111711 | 17
18
1913211 | 3 | 21
20
21
22192325271 | 9 | 23 | 25 | 27
2377
242323
25
262323
275195 | 19
285 | 19
2977
30
31
325155 | 15
33
Sheet3


Regards,
Moti
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Given the type of values in your cells, this should work...
Excel Formula:
=SUBSTITUTE(TRIM(C7&" "&D7&" "&E7&" "&F7&" "&G7)," "," | ")
 
Upvote 1
Solution
Given the type of values in your cells, this should work...
Excel Formula:
=SUBSTITUTE(TRIM(C7&" "&D7&" "&E7&" "&F7&" "&G7)," "," | ")
Hello Rick Rothstein, yes your formula worked flawless

I appreciate your kind help.

Good Luck

Kind Regards,
Moti :)
 
Upvote 0
VBA Code:
Option Explicit
Sub test()
Dim lr&, i&, j&, rng, res(), st As String
lr = Columns("C:H").Find(What:="*", After:=Range("C1"), LookIn:=xlValues, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False _
        , SearchFormat:=False).Row
rng = Range("C6:G" & lr).Value
ReDim res(1 To lr, 1 To 1)
For i = 1 To UBound(rng)
    For j = 1 To UBound(rng, 2)
        If rng(i, j) <> "" Then
            st = st & IIf(st = "", "", " | ") & rng(i, j)
        End If
    Next
    res(i, 1) = st: st = ""
Next
Range("H6:H100000").ClearContents
Range("H6").Resize(UBound(rng), 1).Value = res
End Sub
 
Upvote 1
VBA Code:
Option Explicit
Sub test()
Dim lr&, i&, j&, rng, res(), st As String
lr = Columns("C:H").Find(What:="*", After:=Range("C1"), LookIn:=xlValues, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False _
        , SearchFormat:=False).Row
rng = Range("C6:G" & lr).Value
ReDim res(1 To lr, 1 To 1)
For i = 1 To UBound(rng)
    For j = 1 To UBound(rng, 2)
        If rng(i, j) <> "" Then
            st = st & IIf(st = "", "", " | ") & rng(i, j)
        End If
    Next
    res(i, 1) = st: st = ""
Next
Range("H6:H100000").ClearContents
Range("H6").Resize(UBound(rng), 1).Value = res
End Sub
bebo021999, superb! Thank you for giving a VBA option it worked perfect. This is fast also.

I appreciate your kind help.

Good Luck

Kind Regards,
Moti :)
 
Upvote 0

Forum statistics

Threads
1,215,237
Messages
6,123,800
Members
449,127
Latest member
Cyko

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