13

I have a column of Excel cells that's similar to a grocery shopping list and looks as follows:

3 Days Ingredients
2 Apples
1 Jug of milk
3 Bags of mixed vegetables
5 Potatoes

Is there a way to append a character such as a comma or semicolon at the end of every line within the cell so that it appears as follows?

3 Days Ingredients;
2 Apples;
1 Jug of milk;
3 Bags of mixed vegetables;
5 Potatoes;

I know that there are ways to append to the end of a cell, but I was wondering if there's a way to do it line by line within a cell.

2
  • 6
    (Just FYI, if you can, you probably don't want to return this all in a single cell. It'll be very tricky/annoying to do anything with the data after you have it. I can't think of a reason to return the items in a single cell, instead of one cell per item.)
    – BruceWayne
    Feb 27, 2019 at 2:15
  • 1
    Personally, when I need to do this kind of thing, I always have a standard text editor open side-by-side with Excel (you just want any editor that can handle special characters such as newlines, and also do block selection - Notepad++ is a common one, but many others can do this.) and I'll just copy/paste the text into the text editor, do the operations there (where it's generally much easier) and then copy/paste back into Excel. Feb 27, 2019 at 15:04

3 Answers 3

34

Use Substitute:

=SUBSTITUTE(A1,CHAR(10),";" & CHAR(10)) &";"

CHAR(10) is the Line Return.

Make sure the wrap text is on for the target cell

enter image description here

5
  • Is there also a similar way for adding the char at the beginning instead at the end?
    – undefined
    Feb 27, 2019 at 7:38
  • =";" & SUBSTITUTE(A1,CHAR(10),CHAR(10) & ";") should work. I did not try it.
    – aloisdg
    Feb 27, 2019 at 10:00
  • 9
    Note that if the content uses CR LF as a line separator (which is standard on Windows), you're inserting the semicolon between the carriage return and the line feed. This can cause all sorts of weirdness, and I certainly don't recommend it.
    – Erik A
    Feb 27, 2019 at 10:52
  • Wouldn't it be better to find the line separator and insert relative to that instead? As in, find it, insert at pos -1?
    – Mast
    Feb 28, 2019 at 4:06
  • @Mast That would let you insert one semicolon, unless you used VBA to have a loop that goes through the text. This lets you insert as many as needed, all at the same time Feb 28, 2019 at 8:21
3

Assuming that every item of the list is in a different row, you can use the concatenation character, '&'.

The formula would be:

=A1&";"

Application example

3
  • line by line WITHIN a cell quoting OP
    – aloisdg
    Feb 27, 2019 at 10:00
  • Ah yes thank you, I was stuck on the first line. Should I delete ? Feb 27, 2019 at 10:02
  • 2
    @Stormweaker: Sounds like it could be useful for future readers who find the question via Google. As long as you don't get downvotes, I'd just leave it. Oh, and welcome to SO!
    – Heinzi
    Feb 27, 2019 at 12:18
3

If you want to do it directly in the cell without using a second column and formulas, you can use custom formatting to achieve it.

In custom cell formats, enter @","

Enter image description here

Then you can apply that format across the full range of cells.

It won't actually exist in the cell contents, but it will be displayed on the screen, and if you copy to another application it will be there.

3
  • This will only apply the semi colon to the end of the text, not to each line as the OP requested. Feb 27, 2019 at 12:50
  • Ah ok I thought he meant "In the cell" no that the list was in the cell Feb 27, 2019 at 12:56
  • @StevenMartin, this one is rare to find ,,, perfect 10 ☺ Feb 28, 2019 at 9:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .