Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Simulating Alt+Enter in a Formula.
Written by Allen Wyatt (last updated March 10, 2023)
This tip applies to Excel 2007, 2010, and 2013
Kirk has a formula that concatenates text values: =A1 & A2 & A3. He is looking for a way to simulate the pressing of Alt+Enter between each of the concatenated values. There are two ways that this can be approached, and both end up with the same results.
The first method is to simply press Alt+Enter between the values as you are entering the formula. For instance, consider the following formula:
=A1 & "[ae]" & A2 & "[ae]" & A3
In this instance, every place that you see [ae] you would actually press Alt+Enter. Thus, you would end up with a formula that looked like this just before entering it:
=A1 & " " & A2 & " " & A3
If you find entering this type of formula distracting, you can always use the actual character code that Excel does whenever you press Alt+Enter. The following formula shows this approach:
=A1 & CHAR(10) & A2 & CHAR(10) & A3
The CHAR(10) inserts a line feed character, which is the same as is done by Excel when you press Alt+Enter.
If, after entering your formula, you don't see the results on separate lines, it is because you don't have wrapping turned on for the cell. Instead you'll see a small square box where the line feed character is located. To see the results of the formula on separate lines, display the Format Cells dialog box (click the small icon at the lower-right of the Alignment group on the Home tab of the ribbon). On the Alignment tab select the Wrap Text check box.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12568) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Simulating Alt+Enter in a Formula.
Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!
If you have a string of text that is composed of digits and non-digits, you may want to know where the digits stop and ...
Discover MoreSometimes it is helpful to have a cell contain the maximum value that has ever occurred within changing data. This tip ...
Discover MoreThe formulas in your worksheet can be displayed (instead of formula results) by a simple configuration change. You can ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2022-12-12 10:01:10
J. Woolley
@Roger
Also, for a comparison of VBA functions with Excel worksheet functions, see https://www.techonthenet.com/excel/formulas/index.php
and for a detailed VBA reference, see
https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/visual-basic-language-reference
2022-12-11 11:29:46
J. Woolley
@Roger
1. The correct VBA function is Chr(10), not CHAR(10). The latter is Excel's equivalent worksheet function.
2. The string concatenation operator & should be surrounded by space characters, but I believe the VB Editor (VBE) does this automatically for your expression.
3. Instead of Chr(10), you could use VBA's constant vbLf, but in this case you must manually add a space character after each vbLf. VBA interprets a numeric constant or variable immediately followed by & as declaration of a Long constant or variable; in this case, & is a Long type-declaration character.
4. Before running your macro, use VBE's Debug > Compile to locate any errors.
2022-12-10 13:58:33
Roger
I have reviewed this tip as I am working on a yearly expense spreadsheet. I have used the &Char(1)& command in some of my other areas of the sheet but not in a macro for a new year. I have the following:
Range("$AF$6").Value = "Account Number: 12345678"&CHAR(10)&"KWH Used:______"&CHAR(10)& "https://p-auth.PowerCompany.com/my-account/sign-in".
When I hit enter the formula looks like this
Range("$AF$6").Value = "Account Number: 12345678" & CHAR(10) & "KWH Used:______" & CHAR(10) & "https://p-auth.PowerCompany.com/my-account/sign-in"
If I run it Excel replies back a compile error. has occurred. I have tried looking on line but nobody addresses it being in a macro using a .value function. Can anyone tell me what I am missing in the above examples.
2019-07-09 10:01:26
I have a download from my HRIS that exports job titles into a single cell with wrapped text and two hard returns in between so they are separated but still all on one row. To get the titles into separate rows I've had to edit the one cell by deleting the extra returns, inserting a semi-colon between the titles and then using Text to Columns delimited to separate. Then I have to transpose the columns into rows. Sometimes the cell has over 150 titles so this method is quite tedious. Is there a more automated way to get the list of job titles into separate rows?
2016-01-08 14:26:11
Tim Coddington
CHAR(10) is a line feed, not a carriage return-line feed. Many systems do not return the carriage when a CHAR(10) is encountered. Excel chooses, like many other systems to do so, but is is a choice, not a definition. CHAR(13) is the explicit carriage return.
2016-01-07 07:05:05
Kevin
Sorry for being not quite on topic but is there a method to get the Excel shortcuts back to their defaults.
In particular a Ctrl + Shift + End that is not highlighting the whole selection. It just goes to the last cell like its Shift doesn't get seen. Shift key works in normal operation.
Windows 10 so haven't had any success trying the terms referred in this tip.
2016-01-06 08:18:26
Chuck Trese
The vbLf and vbCrLf constants can be used in macros, but not in formulas.
2014-08-25 03:19:59
Aj
Thanks very much
2013-10-08 04:58:01
Barry Fitzpatrick
In Excel 2010 (and maybe other versions) when saving the file as a PDF and an "unknown char" is also printed (a question mark inside a square box), this doesn't display in Excel only in the PDF version.
The only workaround I've found so far is to pad out, at the point I want the break to occur, with lots of spaces.
Can anyone suggest an alternative?
2013-03-25 10:04:17
Duncan
I think vbLf is a predefined constant for linefeed, equivalent to CHAR(10), and vbCrLf is CarriageReturn + LineFeed
2013-03-24 00:24:32
Juan
Thank you very much for this tip, it's very nice!
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments