VBA add a separtor at the end of the cell

JoeRooney

Board Regular
Joined
Nov 27, 2017
Messages
169
Office Version
  1. 365
Hi, I have the below code which joins all of my cells into one column, now I would like to add a "|" separator at the end of each cell before they are joined into one cell. If someone could advise the best way to do this in this code that would be great.

Code:
Sub JoinCells()

Dim lastrow As Long
    lastrow = Range("A" & Rows.Count).End(xlUp).row

Columns("A:A").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("A3").Select
    ActiveCell.FormulaR1C1 = "ISI File"
  
  Range("A4").Select
    ActiveCell.FormulaR1C1 = Join(Application.Index(Range("B4:AEN4").Value, 1, 0), "")
  Range("A4").AutoFill Destination:=Range("A4:A" & lastrow)
 
End Sub


At the minute I am creating a new sheet and using this code but I think I should be able to do it in the original sheet. Any help is greatly appreciated

Code:
Range("A4").Select
    ActiveCell.FormulaR1C1 = "=POL!RC&""|"""
    Range("A4").Select
    Selection.AutoFill Destination:=Range("A4:AEO4"), Type:=xlFillDefault
    Range("A4:AEO4").Select
    Selection.AutoFill Destination:=Range("A4:AEO" & lastrow), Type:=xlFillDefault
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
If you just want the pipe character in the joined data, replace this line:
Rich (BB code):
ActiveCell.FormulaR1C1 = Join(Application.Index(Range("B4:AEN4").Value, 1, 0), "")
with this:
Rich (BB code):
ActiveCell.FormulaR1C1 = Join(Application.Index(Range("B4:AEN4").Value, 1, 0), "|")
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,521
Members
449,088
Latest member
RandomExceller01

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