I discovered a trick, but Excel doesn’t want to cooperate fully… but maybe there’s a workaround…?
I often end up with a date/time on a “tall row” (since other columns are multi-line):
…and I’d like to save vertical space by splitting the date/time onto 2 lines, while keeping it a single numeric value for reasons of sorting, etc:
I realized that this can be accomplished by using a
␊LineFeed character in the custom number format, one of two ways:
Method #1: On a keyboard with a numeric keypad:
Select the cell with the value.
Hit Ctrl+1 to open the Number Formats dialog.
Customcategory and then in the
Drag between the row headers to make the row twice as tall:
Wrap Textis not already on, click it on the Home tab of the ribbon:
👉 Alt +
0010 enters a
Note: Since Excel doesn’t expect this character, the first line you enter in the
Typebox will disappear as soon as you enter the
␊LineFeedcharacter. There’s no way to see it within the dialog (without deleting the
␊LineFeed), but it’s still there.
Method #2: On a keyboard without a numeric keypad and/or using VBA:
In the VBA Editor, either within your procedure, or in the Immediate Window (Ctrl + G), you can set the number format for
A1 with something like:
Range("A1").NumberFormat="yyyy-mm-dd" & vbLf & "HH:mm am/pm"
Chr(10)) represents a
␊LineFeed character in VBA.
This is cool, but it seems that Excel still treats the value like it’s one long string on a single line.
This is demonstrated by:
- double-clicking between column headers to AutoFit the column:
The column does not “shrink” any further.
- double-clicking between row headers to AutoFit the rows:
The row does not “grow to double height”.
manually dragging the column to a narrower size.
Excel “thinks” the value doesn’t fit:
<img src="https://i.stack.imgur.com/TuBAZ.png" alt="Img
Any ideas for a workaround?
Perhaps there’s a hack to force Excel to display partial values instead of
when a formatted numeric value doesn’t fit?
You have to shrink-wrap it. See the OP’s edit here:
1) Go to the Alignment tab in the Format Cells dialogue.
2) Select “Shrink to fit”.
3) Select “Wrap text”.
4) Click “OK”.
Excel will still auto-size the column to ~139 pixels, but you can drag the column width to ~71 pixels and still see both lines.
Make sure the Shrink to fit function is ticked
Go to: Right click on cell –> Format Cells –> Alignment –> Shrink to fit