Suppose I have this content 8.XY in an Excel cell. I would like to add leading zeros such that it looks like 0008.XY. The converted value will always have 4 digits in front.
Other examples are 78.XY becomes 0078.XY. 188.XY becomes 0188.XY. 1123.XY remains 1123.XY. What Excel formula can I use to achieve this?
Assuming your string to be checked is in cell A1, use
=IFERROR(REPT("0",5-FIND(".",A1)),"")&A1
The IFERROR function is used in case your string has more than 4 characters before the period.
The following formula will do what you want by essentially converting your data to a string, where I have used G2 as the cell with your data in. =IF(FIND(".",G2,1)-1=4,G2,IF(FIND(".",G2,1)-1=3,"0"&G2,IF(FIND(".",G2,1)-1=2,"00"&G2,IF(FIND(".",G2,1)-1=1,"000"&G2,"0000"&G2))))
There are apparently more than one way to crack an egg, as evidenced by the number of working answers.
Another way, again assuming your string to be checked is in cell A1 could be to use the CHOOSE function which I prefer over nested IFs because of its clarity.
=IFERROR(CHOOSE(FIND(".",A1),"0000","000","00","0",""),"")&A1
IFERROR is used in case the string has five or more characters before the period.
CHOOSE selects a value or action to perform based in the index number in the first function parameter.
Based on your statement that the number will always have 4 digits in front of the decimal.
=right("000"&A1,7)
The above also assumes you will only have 2 characters after the decimal point.
If you have the possibility of having more than 4 character in front of the decimal point, you could use the following:
=if(FIND(".",A1)<5,right("000"&A1,7),A1)
Again this assumes only 2 characters after the decimal point.
IF you are just interested in displaying your integer with leading 0 and a trailing .XY, then you could format your cells to display that. In order to achieve this follow these steps.
1) Select the a cell or the range of cells with the data you want changed.
2) While those cell are selected, go to the "HOME" ribbon and select the drop down menu adjacent to GENERAL.
3) From the menu that is displayed, select "More Number Formats".
4) In the window that comes up select "Custom" in the Category window.
5) In in the Format Bar enter: 0000".XY" .
6) Copy cell formatting to other cells as required.
Another Method to Achieve
Assuming your strings starts with A1 and A2 and so on (Please refer the snap below).
Apply the below formula in B1 and drag down
=REPT("0",4-(SEARCH(".",A1)-1))&MID(A1,SEARCH(".",A1)-(SEARCH(".",A1)-1),LEN(A1))
Related
I have in a cell two numbers "=5+4" as a text. This is a result of another operation.
I took a part of another formula and concatenated it with "equal" symbol:
= "=" & RIGHT(FORMULATEXT(V8);LEN(FORMULATEXT(V8))-SEARCH("+"; FORMULATEXT(V8)))
I want to get the result of 5+4 in a cell- which means "9" ;)
I DO NOT WANT TO USE VBA code.
my initial problem was to extract all numbers except the first one from an equation and sum in another cell: A1: "=6+5+4". A2: "9". Maybe it can be solved without VBA?
You could try (assuming only addition):
Formula in B1:
=SUM(FILTERXML("<t><s>"&SUBSTITUTE(MID(A1,2,LEN(A1)),"+","</s><s>")&"</s></t>","//s[position()>1]"))
In fact, if you don't want to use the 1st number we could also discard taking '=' into account:
=SUM(FILTERXML("<t><s>"&SUBSTITUTE(A1,"+","</s><s>")&"</s></t>","//s[position()>1]"))
And since SUM() will ignore text in the final answer, we can now even further simplify this (thanks #JosWoolley):
=SUM(FILTERXML("<t><s>"&SUBSTITUTE(A1,"+","</s><s>")&"</s></t>","//s"))
If you are always adding 2 numbers, then you can use this:
=VALUE(VALUE(MID(A1;2;SEARCH("+";A1)-2))+VALUE(MID(A1;SEARCH("+";A1)+1;9999)))
My column A is formatted as text, and all values follow same pattern: =Value1+Value2
So the formula extracts Value1 and Value2 as text with MID functions, based on the position of + symbol. Then Excel convert both values into numeric with VALUE function. Notice there are 3 values, the third one is to make sure the cell stays at standar format (in some versions of Excel, like mine 2007, when involving text formatted cells into formulas, the formulated cell autoformat itself to text format, making the formula to work just once).
As you can see in the image, it works perfectly but this is just for pattern =Value1+Value2. For different patters you'll need different formulas.
If you want to make a formula to work with all patterns, then indeed you need VBA.
I'm stumped in Excel (version 16.0, Office 365). I have some cells that are formatted as Number, all with values > 0, but when I use the standard SUM() on them, it always shows a result of 0.0 instead of the correct sum. When I use + instead, the sum shows correctly.
For example:
SUM(A1:A2) shows 0.0
A1 + A2 shows 43.2
I don't see any errors or little arrows on any of the cells.
Excel is telling you (in an obscure fashion) that the values in A1 and A2 are Text.
The SUM() function ignores text values and returns zero. A direct addition formula converts each value from text to number before adding them up.
Using NUMBERVALUE() on each cell fixed it. Even though each cell was formatted as a Number, since the data was originally extracted from text, the cell contents apparently were NOT being treated as a Number. Yet another flaw in Excel.
I get a similar issue while importing from a csv.
Selecting the cell range and formatting as number did not help
Selected the cell range then under:
Data -> Data Tools -> Text to Columns -> next -> next -> finish
did the job and numbers are now turned into numbers that excel consider as numbers !
This avoids use of NUMBERVALUE()
There is a much faster way you just need to replace all the commas by points.
Do control-F, go to "Replace" tab, in "Find what" put "," and in "Replace with" field put "."
I noticed that if the sum contains formulas if you have any issue with circular references they won't work, go to Formulas-->Error checking-->Circular References and fix them
If there's a tab in your .csv then Excel will interpret it as text rather than as white space. A number next to a tab will then be seen as text and not as a number. Convert your tabs to spaces with a text editor before letting Excel at it.
I have one cell containing several lines, including numbers inside brackets, which I want to sum-up with a single Excel formula (no VBA).
The following approach already works for single bracket:
https://exceljet.net/formula/extract-text-between-parentheses
But I need extended approach... here an example for the content of one single Excel cell to which I search for an formula, which should result in sum of "8":
The task requires following effort (incl. documentation)
- create plan (2h)
- execute test (14h)
- write report (draft) (2h)
Possible approach: The formula should search for all numbers inside the mask <"(" x "h)">, where x must be summed-up.
UPDATE: The formula should also work with numbers >=10.
UPDATE2: It should also work in case there are other comments in brackets, also after presence of first (xh) number. See "(draft)" in example, last row.
Borrow the formula from this post #6 (https://www.mrexcel.com/forum/excel-questions/362184-extracting-multiple-numbers-string.html) and modified to fit your need (single cell formula). Assuming you are going to enter the formula in cell B1:
{=SUM(VALUE(MID(0&A1,LARGE(ISNUMBER(--MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))*ROW(INDIRECT("1:"&LEN(A1))),ROW(INDIRECT("1:"&LEN(A1))))+1,1)))}
Basically this is to assign each character with its index and then get the numeric value to sum up. Please note this is an array formula. Please click Ctrl + Shift + Enter together.
REVISED:
Here is the array formula (click Ctrl + Shift + Enter together) to extract two-digit numbers:
{=SUMPRODUCT(IFERROR(0+("0"&TRIM(MID(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(LOWER(MID(A1,SEARCH("h)",A1)-4,LEN(A1))),"h",""),")","("),"(",REPT(" ",1000)),ROW(INDIRECT("1:20"))*2*1000-999,1000))),0))}
What this does is to massage the text first by removing unnecessary content, remove h wording and convert ) to 999 blanks. Then you can extract numbers and add up. IFERROR will made the anything not numbers to 0. Hope this can solve your problem.
I appreciate that this is not in any way elegant, however it is working. I do not have time to run through the logic here right now (might edit it in later though) but essentially it is a load of search index logic.
I have Used 5 columns for each formula which assumes a maximum of 5 values but you can adjust this as needed by dragging the formula over more columns as it will begin looking for the next "(?h)" after the previous column's found value.
Red cell formula: =SEARCH("(?h)",$A1)&" - "&SEARCH("h)",$A1)
Orange cell formula: =SEARCH("(?h)",$A1,MID(B1,SEARCH("- ",B1)+2,LEN(B1)-(SEARCH("- ",B1)+1))*1)&" - "&SEARCH("h)",$A1,MID(B1,SEARCH("- ",B1)+2,LEN(B1)-(SEARCH("- ",B1)+1))+1)
Yellow cell formula: =MID($A1,LEFT(B1,SEARCH(" - ",B1))+1,((MID(B1,SEARCH("- ",B1)+2,LEN(B1)-(SEARCH("- ",B1)))*1)-(LEFT(B1,SEARCH(" - ",B1))*1))-1)*1
Green cell formula: =SUMIF(G1:K1,">="&0)
I have a spreadsheet (Google spreadsheet) where I register information about employee´s education. In the bottom of each column (every employee is represented by a column) I want the cell to display "Yes" if there is text in two other specified cells. (Not if there is text in only one of them, or none of them.)
I have tried all kinds of combinations using AND and IF and NOTBLANK, but I probably have the wrong syntax, or use the functions wrong.
So what I need help to understand is if there is text in cell B3 and in cell B34, how can I create a formula that displays the text "Yes" in cell B38?
Please try:
=if(and(not(isblank(B3));not(isblank(B34)));"Yes";"No")
This may cover a wider range of possibilities than you require but it is usually easeir to trim back than to expand. For example, If either B3 or B34 is empty, this formula returns No, rather than nothing at all (but the No is not obligatory) and the "text" in B3 and B34 can be either alpha or numeric, or a mixture.
Please try this, it works:
=IF(OR(ISBLANK(B3),ISBLANK(B34),NOT(ISTEXT(B3)),NOT(ISTEXT(B34))),"No","Yes")
Logic:
If any of Cell B3 or B34 is blank or contains Non-Text value is returns "No". It just returns "Yes" only if both the cells have a "Text" value.
More short and powerful Formula as per your requirement is as follows:
=IF(AND(ISTEXT(B3),ISTEXT(B34)),"Yes","No")
lets say I have a xls sheet with just one column which has the following content:
1
2
3
3
4
5
5
6
You see there are some cells with equal content.
Now I want Excel to format (e.g. background) all cells which are there twice.
I would say that conditional formatting is the right way but there I always have to enter a certain cell.
Is there any possibility to do this?
Best,
Elias
I do this routinely. Start at the second cell and select the rest. Choose Conditional Formatting, as you thought, select VALUE IS EQUAL TO, and click the cell above (let's call it A1). Here's the trick: it will enter this as an absolute reference - $A$1 - but you need to strip out the dollar signs, so it is relative. Now (of course) assign a background color, or whatever style you want, and the first cell in any sequence of identical values will have normal formatting, but subsequent cells will have the style you choose.
This isn't exactly what you've asked for - the first 3, for instance, will still have normal formatting - and I'm not sure I know a way to get all the duplicated cells, including the first, styled differently. But it's a start...
Select A1:A8 and enter this conditional format - Formula Is
=COUNTIF($A:$A,A1)>1
and set a format. It will format anything in column that appears more than 1 time.