How to shrink column width with multiple-line custom number formats? - excel

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.
Choose the Custom category and then in the Type: textbox:
Enter the first part of your custom format, ie. yyyy-mm-dd
While holding down Alt enter 0010 on the numeric keypad, and then release Alt
Enter the second part of your custom format, ie. HH:mm am/pm
Hit Enter.
Drag between the row headers to make the row twice as tall:
If Wrap Text is not already on, click it on the Home tab of the ribbon:
👉 Alt + 0010 enters a ␊LineFeed character.
Note: Since Excel doesn't expect this character, the first line you enter in the Type box will disappear as soon as you enter the ␊LineFeed character. 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"
...then adjust the row height and make sure Wrap Text is on, via VBA or with steps #5 & 6 above.
👉 vbLf (or Chr(10)) represents a ␊LineFeed character in VBA.
My issue:
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:
               
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?
Thanks!

You have to shrink-wrap it. See the OP's edit here:
Prevent hash signs (#) showing up in Excel without changing cell format or width
Go to the Alignment tab in the Format Cells dialogue.
Select "Shrink to fit".
Select "Wrap text".
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

For this example, you can split on two cells instead of doing that. On the first cell, just put the date format without time. On the second cell, do a formula =(the first cell), but put it in time format.
I am looking at a way to shrink this to fit on multiple lines in a cell, but it looks like we don't have the technology to do that automatically in 2020.

Related

Repeat cell content in excel to fit its width or height

I have columns with merged cells, that the content dispears in other pages of the document, I want some how to repeat the content to make sure that it apears in every page, so to make this clear consider the followkng sinario:
For a cell that contains a letter C for exemple, how to make excel generates other Cs with some spaces between them in the cell to fill the new width?
There could be a text in the cell to be repeated.
Is there any function to do that?
Edit:
I tried with print titles, but since the column contents changes, it does not work.
You can achieve this result using a custom cell format. For example:-
Set a Custom number format of *C# for the cell.
Enter a single C in the cell.
The cell will fill with Cs.
The asterisk tells Excel to repeat the character that's following. In this case the character that follows is a "C". The final # specifies that the cell should contain text. You can replace this with a 0 (zero) or a more complicated format (like in number formatting).
What happens, then, is that the "C" you entered will be preceded by the number of fill characters the cell can take. If you enter "John" the display will be CCCCCCCCCCJohn. The Formnat *=0.00 would show the number 55.1234 as ==========55.12
The sequence can be reversed with a format like # *+ which would produce a output like "John +++++++++++".
Unfortunately, I don't know of a way to repeat more than one character, even if the second character is a space. For this kind of thing Excel has the RPT() function. =RPT("C ",5) will repeat a C, followed by a space, 5 times. Unfortunately, the RPT function doesn't seem to accept Char(10) (Alt + carriage return), limiting its use to fill cells vertically. Also, one would have to adjust a cell to the width of the function's output instead of the output being adjusted to fit the cell width.

How to make excel stop treating column as date

My column values are as follows:
1-1
1-2
2-1
2-2
...
12-1
12-2
13-1
13-2
...
n-1
n-2
On cells containing 1-1 up to 12-2, excel doesn't meddle with me, but starting on 13-1 up to the nth row, it shows warning "Text date with 2-digit year". Unfortunately, this are really not dates. Also, I already tried formatting the said rows/cells as text before inputting any values, but really when excel sees "13-1" and above, it shows the error. How should I fix this?
Additional info: when the rows are shown using formula, there are no errors, but sadly, using formula is not an option and I need values as is.
You can type ="1-1" instead of just 1-1
When you type 1-1, excel change this to 1-Jan. When you type ="1-1" , Excel treat the value as string. Hope it helps.
Just right click on the column click on Format Cells ... on Number Tab on Category List select Text, this will make anything you enter or have as a text.
But if you are copy paste data then use Match Destination Format (M), just right click on the cell and select Match Destination Format (M) not Ctrl-V.
If you add a single quote to the start of the dates Excel treats it as a string. Works for numbers as text too
Stop excel from converting copy-pasted number/text values to date
Copy the original data
Paste to Notepad / Notepad++
In Excel, change the Format Cells / Number Format (that shows "General" as default) to TEXT
Copy your data from Notepad
Paste back to the Excel cells, in which you have changed the format to TEXT
Turn off error checks for those types of errors.
With Application.ErrorCheckingOptions
.TextDate = False
.NumberAsText = False
End With
Also found within File, Options, Formulas, Error checking rules.

Long Numeric Strings

When generating data/item's code that resembles a scientific number (e.g 124E12) from Progress to Excel, Excel will display it on cell as 1.24E+10. I tried to set excel's cell as text and general before generating but it will still treat it as Scientific. Also tried to use Number and it displayed 124000000000000.
You need to change the display format in Excel.
I'm on a Swedish version of Excel so names below might not be translated the right way.
1) Select the cell/row and right-click. Choose Format Cell in the menu.
2) Choose "Custom format" or similar (in the end of the list).
3) Type ##0,000E+00 and press "OK".

Can Not Get My VLookUp In Excel To Return The Requested Data

Can Not Get My VLookUp In Excel To Return The Requested Data
I am trying to pull data from another sheet based on data selected from a dropdown on the main sheet.
All the formatting is "General"
=VLOOKUP(F15737,'Location Master'!$A:$J,2,FALSE)
It just keeps returning me #N/A
Try using the Index Match method. It's an alternative to Vlookup which doesn't require data to be sorted and can therefore be of more use.
The typical structure of this method is (the text inside the asterisk will give the ranges specific to your sheet:
=INDEX (**Column from which you want to return a value**, (MATCH(**Lookup Value**, **Column against which you want to lookup**,0))
In this case, if I've understood your workbook structure, the formula should look like this:
=INDEX('Location Master'!$B:$B,(MATCH(F15737,'Location Master'!$A:$A,0)))
This is a common problem with VLOOKUP(). Most likely you have some whitespace (A tab character or some spaces) after one of the values. Click on F15737 and see if there are any spaces at the end of it. Likewise, manually find the value in 'Location Master'!$A and check it for spaces or tabs after the value.
If the whitespace is found in F15737 then you can change your vlookup to be:
=VLOOKUP(TRIM(F15737),'Location Master'!$A:$J,2,FALSE)
If the whitespace is in the range to which you are looking up, then you'll need to trim all of those values, which you can do pretty quickly in a new column with the TRIM() formula.
If this doesn't solve the problem then you might have a number stored as text. Generally excel will tell you if this is the case within the cell with a little green corner indicator. To get Excel to automagically change a column from a "Number stored as Text" to a proper number you can:
Highlight the column
Go to Data>>Text To Columns
Click "Fixed Width"
Click "Finished"
Excel will then format everything automatically (dates to dates, numbers to numbers, text to text, time to time, etc.)

How to make sure all excel cells formatted as text in a column actually are

I have a column of content submitted by multiple users, generally pasted into a sheet, from multiple sources. This column has numbers that should always be formatted as text.
In fact, no matter how this is done, there are always a few items that never have the indicator in the left corner warning that these are formatted as text (which we want to see in all cases)
Checking the individual cell, it does show as formatted text, but in reality on an import into a datatable, if the indicator is missing, the datatype is imported as a number.
Clicking after the number and hitting Enter will change the indicator to text.
How can I do that in VBA? I don't want to visit each cell, click on the end of the content and hit enter.Cutting and paste special in no combination reliably fixes these.
What does excel look at, which gets the format issue right with these text format warning indicators, and yet doesn't seem to get it right when you look at the cell format properties?
Excel 2003 but have had the same issue in later versions too.
What worked for me was to check the error indicator, which seemed more reliable than the cell format itself. This looks for anything missing the indicator and forces it to be text.
Unless someone knows something further concerning why this should NOT be done, it solves my issue.
Sub check4textformat()
For Each cell In Range("E2:E15000")
If cell.Errors.Item(xlNumberAsText).Value = False Then cell.Formula = cell.Text
Next
End Sub
You really only need to prepend the text indicator character "'" before every number. Assuming that your values are in the first column, in the first 120 rows, you can do it like this:
For i = 1 To 120
Me.Cells(i, 1).Value = "'" & Me.Cells(i, 1).Value
Next i
If the cell already has a text value, the prepending is ignored. When copying (and when obtaining the value in VBA) the "'" is completely ignored as it only indicates the "type" of the cell contents.
Since your main target is not visiting each cell, I will suggest an easier way than VBA (actually, it's probably the easiest way).
Select the desired column.
Go to Data > Text to Columns.
Select "Delimited" (should be already selected by default) and press "Next".
Uncheck all delimiters and press "Next" (you can also leave the default state of "Tab" as the only delimiter).
Under "Column Data Format", select "Text" and click "Finish".
Done. All the numbers in the column should be stored as text now.

Resources