The answer is, as tlewin said
=ConcatenateRange(A1:A4,CHAR(10))
Or alternatively, using [alt-enter] you could write it like this
=ConcatenateRange(A1:A4,"
")
"But wait," you say, "I tried that and it does not work!"
Well, you see, when you manually enter something like I[alt-enter]am[alt-enter]a[alt-enter]boy
in Excel, or even execute a statement such as [A1] = "I" & vbNewLine & "am"
Excel automatically changes the cells formatting and turns on word wrap. Word wrap is required for linebreaks to be shown in a cell. However if you return a string with a linebreak in it from a UDF Excel does not update the format.
I can think of two possible solutions:
- Manually enable word wrap on any cell you use this function in
- (Not recommended) Store the reference in
Application.Caller
during your ConcatenateRange UDF call, then set an Application.OnTime(now, "AddWordWrap")
call and write the AddWordWrap subroutine so that it uses the stored reference to add the wordwrap formatting to the cell (this is because you cannot update the cell's format in a UDF). This method is buggy and problematic.