Excel (VBA?) - Custom Cell Formats, number and text spacing - excel

I am working on an excel sheet that tracks report numbers. The report numbers all follow the same sequence.
XX########X##, where X is a letter and # is a digit 0 thru 9. All report numbers are 2 letters followed by 8 digits, then 1 letter and then 2 more digits.
The numbers/letters are not random but identify what is contained in the report. So, it's custom to refer to them in a specific cadence which is:
XX ### ##### X##.
As you can see, this pattern is so much easier on the brain than the above.
Like how phone numbers are all said in a specific ###-#### pattern or SS is ### ## ####.
Anyway, I would like the column that these report numbers are in to "display" with spaces. I put display in quotations because I don't want to actually have a space character in the cell. This will affect other parts of the spreadsheet downstream.
Excel has built in cell formatting options (Format Cells > Custom). I am able to use to create a spacing pattern using zero (0).
E.g. if my file reports were all numbers "1234567891234" I can input a custom pattern as "00 000 00000 000" and it will "display" "12 345 67891 234". However, I cannot get this to work with text and numbers. I have tried "*", "#", "?" but no luck. I am unable to find a solution in VBA but I suspect that is the way to go.
Thanks!

The cells contain text. Text formatting cannot be changed with a number format. Text will always shows as entered in the cell. If you want to see spaces, there will need to be spaces in the cell.
You don't specify where the data comes from. If it is not entered manually, but loaded from another system, you could use a formula to add the spaces in the specific places and then hide the original column.
=LEFT(A1,2)&" "&MID(A1,3,3)&" "&MID(A1,6,5)&" "&RIGHT(A1,3)
or
=REPLACE(REPLACE(REPLACE(A1,11,0," "),6,0," "),3,0," ")

Related

reformat excel text column to specific format

I have a column in my excel that includes authors name and it looks as follows:
My goal is to remove the dates + the last comma from all of these rows to make it something like this:
Is there a way I can do it in excel?
Based on your example, in which there are multiple commas in one cell, I would go with determining the position of the last comma first (in order to know where to slice the content of said cell). Then it's a matter of IF formula based on condition in which the last 4 characters in the cell are digits:
=IF(ISNUMBER(VALUE(RIGHT(A1,4))),LEFT(A1,FIND("#",SUBSTITUTE(A1,",","#",LEN(A1)-LEN(SUBSTITUTE(A1,",",""))))-1),A1)
FYI: The "#" substitution is targeted at knowing exactly where the last comma occurs in the cell. Any other unique, not-appearing-in-the-string character would have done the same job.
I've tested the formula on below examples:

Excel. Special number separator format for 1 specific column, no for the entire document

In an Excel's document, I need when you enter a positive 6 digits number (XXXXXX) into a specific cell like for example, the number 223715, then Excel automatically format the number as 223'71'5 once you write the number into the cell and you press Enter or move to another cell, etc.
In addition to the previous explained, I need when you enter a 5 digits number, then Excel automatically adds an ending '0' to complete the number format to 6 digits, so if you insert the number 22589, then Excel automatically converts it to 225'89'0
The most important part is I need to give this "special" format ONLY in one single column or defined set of specific cells, because for example, I tried modifying an Excel's setting that allows to use the number separator you want but it takes effect in the entire document that is exactly what I don't need, because I need to mainly have the Excel documents in a standard way but with some columns/cells with this special format.
I tried with multiple custom Number Cell Format like "###'##'#0.00", "###'##'#000'00'0" and similar combinations trying to get positive results but no luck for now.
EDIT:
Try this custom format: [<=99999]###'##'\0;###'##'#
5 digits
6 digits

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.

Formatting numbers for a barcode as text for readability in Excel 2013

Is there a way to format text is a specific way similar to how one would format a number? I'm attempting to display a barcode's numbers within a cell in a more readable format. I'm using UPCs, and because a UPC has a leading zero, I can't use number formatting if I want to keep the leading zero stored, I need to store the barcode as text. Is there any way I can store the barcode within the cell like this:
but have my cell display like this:
I've tried custom number formatting of 0 00000 00000 0;#, but this will truncate the leading zero in the data (seen below), and simply display a leading zero. This breaks some conditional formatting on the cell where it checks the length of the data within the cell and if the length is not equal to 12 (the length of a UPC), the cell will have a red fill.
Data:
Display:
Could you create a second column showing the barcode in the format you want using something like (if your barcode of 12 digits in in cell A1):
=Left(A1,1)&" "&mid(A1,2,5)&" "&mid(A1,6,5)&" "&right(A1)
Not exactly what you're looking for but maybe a workaround?
You may try changing the conditional formatting rule(s). Take for instance the rule is looking at A2's length, make this portion as TEXT(A2, "0 00000 00000 0;#") and change the length criteria from 12 to 15.
But still, if the barcode value is 7 digits, the formatting will convert this to 15 characters (filling 5 leading zeros) in any case and the conditional formatting will not be working properly & will show that the cell's length is OK every time.
In this case, the best solution might be is to convert the barcode column to text (so in this case the leading zeros will remain), and create a helper column with below formula; your conditional formatting will still be looking at the old text column but you will be using this new column, maybe hide that old column:
=NUMBERVALUE(A2)

How to remove a single Leading space in the numeric column in Excel 2013

I really tried a LOT with in-built functions and also with google search but none of the ways doesn't worked out for expected result.
My exact problem is:
I've few numeric columns which i got from a website and copied directly into excel.
In those columns there is a SINGLE Leading space at the beginning of each number in the cell of the entire column. Example 523946.00. In this number there is a single space before the digit 5.
I tried a lot with TRIM and SUBSTITUTE in-built functions but nothing able to resolve my problem of removing spaces.
And also my expectation is when i select two or multiple cells in the same column(spaces removed) then automatically Excel should show or display the AVERAGE: <Average value> SUM: <total Sum> COUNT: <count value> at the below status bar or bottom ribbon.
Say, AVERAGE: 175.49 COUNT: 2 SUM: 350.98
This type of information is not showing at the bottom. Only i'm able to see COUNT: 2 alone....why?
I want in General Format only. No any special formats.
I'm using MS Excel 2013
Edit:
You can actually just use find and replace.
Copy one of the trouble cells.
Select all the cells containing non break space, and select find and replace.
Paste the copied cell into the find bar, delete everything but the last character (asuming that is the non breaking space).
Leave the replace bar empty and press replace all.
This removes all non breaking spaces. :)
**Old Solution:**You can add nothing with paste special to the whole column where the spaces occur.
First copy an completely empty cell. (! remember this step)
Then select all cells in the column and right click and select paste special.
Then select "add" almost at the bottom (see picture) and press ok.
This will make excel reevaluate the values as if you had modified in and entered the value manually. Excel then correctly converts them to numbers. :)
First make sure you have the column Formatted as you would like. Make sure it is a number with 2 decimal places (or how ever many you need), then also make sure that there is no Indents (Maybe you think the Indent is a space?) And that you have it Aligned to the Left, Or where you want the Data To be. This alone should take care of your issue.
If that doesn't work here a list of possible solutions.
=Value(Trim(A1)) ' Removes all white space before and after the text in A1
=Value(Clean(A1)) 'Removes all non printable Charactersin A1
=Value(SUBSTITUTE(I3," ","")) 'Substitutes(Replaces) all instances of " "(Space) with ""(nothing)
'****Note: With Substitute you can also specify how many
' Substitutes(Replaces) to make of the value
=Value(SUBSTITUTE(I3," ","",1)) ' Same as above but with only remove the FIRST space
=Value(Trim(Clean(A1))) ' Removes all white space before and after the text
' after removing all Non-Printable Characters
=Value(Trim(Clean(Substitute(A1," ","")))) ' Removes all white space before and after the
'after removing all Non-Printable Characters
' And after replaceing all spaces with nothing
=Value(Right(A1, Len(A1)-1)) ' This takes the End of your text by the number of characters
' in the value Except the First (In your case should be the Space)
=Value(SUBSTITUTE(I6,CHAR(160),"")) 'To help with the non breaking spaces also.
If nothing works could you please share Why you would like to remove the space? As in what you are trying to do with the data? As maybe that will open more solutions
With Ole Henrik Skogstrøm's Suggestion added Value around the functions to get the result as a value.
It may be Excel is treating your cells as text data. Is the fun Green Triangle present?
This is a common problem in excel. Forcing numeric is easier than text. Just format a column as number or General and then put in the function value() into the cells.
Things can be cleaned up from there with Copy/Paste Special values and then remove the original column.
Using Excel 2007
brettdj answered this for me. This is what worked for me and it was SIMPLE!!
To remove the CHAR(160) directly without a workaround formula go to
Find & Replace
in the Find What hold ALT and type 0160 using the numeric keypad
then Leave Replace With as blank and select Replace All
In your case, since you always have a string of numbers, where you want to remove just the first character (a space), this formula should work:
=RIGHT(A1,LEN(A1)-1)
The numbers can vary in length, important is only, that you want to remove just 1, (or 2, or 3 etc) characters. It will still work. {If you had 2 empty spaces in front, then you would use in the formula -2, if three -3, etc)
However, if you had always a different amount of blanks in your string of numbers, like I had, you could use this formula, which worked for me:
=VALUE(SUBSTITUTE(TRIM(A1),CHAR(160),""))
,assuming that the issue you are facing is code "160".
That you can find by typing: =code(A1), which in my case gave me the result "160". Therefore char(160) in the formula above.

Resources