Excel: adding multiple h:mm:ss cells - excel

I am attempting to add three cells which I have formatted as hh:mm:ss
and it is giving me incorrect sum as one of them is missing hh
A B c
01:01:01 :01:01 01:01:01 SUM(A,B,C)
is returning 2:02:02 when it should be 2:03:03
I have several cells missing the HH so it is throwing off all my formulas, any way I can force the 00:01:01, on a cell that is :01:01?

Try,
=SUMPRODUCT(TIMEVALUE(RIGHT("00:00"&TEXT(A2:C2, "[hh]:mm:ss;#"), 8)))
The format mask used by the TEXT function (hh:mm:ss;#) converts real time values to text-that-looks-like-time and leaves values that are already text-that-looks-like-time unchanged. Leading zeroes and a colon are concatenated onto the result as a prefix and the right-most eight characters are parsed off with the RIGHT function. This should cover both :00:00 and :00 text values. This allows the TIMEVALUE function to process the resulting text to a true time value. The SUMPRODUCT wrapper produces cyclic calculation so that you don't have to sum three largely redundant formulas.
In the following sample image, note the default left alignment of B2 indicating text while A2 and C2 are right aligned indicating a true number, date or time.

If the values will always be contiguous as you show, you can try:
=SUMPRODUCT(--("00"&A1:C1))
Prepending "00" and the double unary will have no affect on the real time values, but will convert the "missing hour" value to a real time

Related

Timevalue function not working for unrecognized time format

I have a bunch of time data that's formated weirdly, ranging from numbers 100 (representing 1 AM, or 01.00.00) to 2359 (representing 11.59PM, or 23.59.00).
I have been trying to use the TIMEVALUE() function to convert these data, but it just returns #Value?, I guess because the time format 'HHMM' is not recognized without the ' : ' separating them?
What I'd like is to convert it to the HH:MM:SS format, where the SS would automatically be zero.
Use REPLACE:
=--REPLACE(A1,LEN(A1)-1,0,":")
Then format it as desired.
If your text values are consistent, this can be carried out by using a formula that splits the value by the number of characters and then recombines the split values into a time value.
All formulas assume that your weirdly formatted text value is in cell B2
=IF(LEN(B2)>3,LEFT(B2,2),LEFT(B2,1))
This formula works out the first (hour) element of a time, if the text string is greater than three characters it will take the first 2 characters of the string (23), if its less than 3 characters it will only take the first character (1)
=RIGHT(B2,2)
This formula takes the second (minute) element of the time.
=TIME(C2,D2,0)
Finally this formula converts the two text elements into a string
C2 = The cell with formula 1 in it
D2 = The cell with formula 2 in it
This could all be written as the following formula if needed
=TIME(IF(LEN(B2)>3,LEFT(B2,2),LEFT(B2,1)),RIGHT(B2,2),0)

Excel custom formatting numbers (0 especially)

Based on this comment fom SoftTimur I did some testing on formatting and came across the following problem:
If I put =SEQUENCE(4,,-2) in A1 and custom format the range with 0;-0; it'll show the values as I intended.
If I sum the spill range in A6 using =SUM(A1#) it shows the correct value (-2).
If I put the following in B1: =TEXT(SEQUENCE(4,,-2),"0;-0;") I expected the same result as above. However Excel sees it as text (by default aligned to the left).
If I sum the spill range in B6 using =SUM(B1#) it shows the result 0 while if I sum B1+B2 I get a correct result.
Question 1: What's the explanation of the incorrect sum result in B6 versus the correct one in B7?
Question 2: Is there a different way to display a zero as blank, but keep the ability to calculate the range containing that value?
Question 1:
The TEXT function returns text and computers can't add text strings together. They can only add numbers together.
Excel will sometimes automatically perform type conversions to allow formulas to deliver what Excel guesses as being the expected result. In this case, it is sometimes turning text into numbers before adding them together. This can make like easier for users but the inconsistency can easily lead to errors.
Say A1 and A2 are formatted as text and contain the text character "1". Excel will do an implicit type conversion for operators (+-*/):
=A1 + A2
It won't do conversion for ranges in functions:
=SUM(A1:A2)
=SUM(A1,A2)
When taking in a range, the SUM function will ignore all text, so that it can still sum the numbers in the range without throwing an error. If all cells in the range contain text it will return 0.
However if you tried to use the addition operator on two cells containing text that can't be converted to numbers, it will throw an error.
Note that when you put "A1 + A2" inside the SUM function, excel first evaluates the addition operation (as this is a single input within the function which must be evaluated first), so it converts A1 and A2 to numbers at this point to create a single numeric result, and then the SUM function takes just the single numeric value as input and returns it again as the total.
If you use SUM with two separate inputs, as =SUM(A1,A2), it doesn't convert either input to a number first.
Question 2:
To get the correct result using the SUM function over the range, you can modify the original sequence formula so that it is delivering numeric values. This can be done in various ways:
1 - Convert the text back to a number by multiplying by 1 (forcing another implicit type conversion), handling the error generated for the nullstring which can't be converted to a number:
=IFERROR(TEXT(SEQUENCE(4,,-2),"0;-0;")*1,"")
2 - Test for 0 using an IF statement and return the null string:
=IF(SEQUENCE(4,,-2)<>0,SEQUENCE(4,,-2),"")
3 - Invert the sequence twice, which throws an error only when it is equal to 0:
=IFERROR(1/(1/SEQUENCE(4,,-2)),"")
OR you can modify the SUM formula to convert the range to numbers on input:
=SUM(IFERROR(B1#*1,0))
However this approach requires you to modify all formulas that look at the original sequence. If the original sequence is intended to be used as numbers (as it is in this case), it is better to have it be generated as numbers in the first place.

Excel Remove Decimal Places

I have an excel formula that is producing a lot of decimal places and I cannot reduce them using the format cell -> numbers -> decimal places options. Here is the formula.
Cell named V01_MIN
V01_MIN =MIN(6:6)
Has a value of 2
Cell named V01_MAX
V01_MAX =MAX(6:6)
Has a value of 1800
Cell named V01_A
V01_A =1-V01_MIN*V01_B
Has a value of 0.889877642
Cell named V01_B
V01_B =99/(V01_MAX-V01_MIN)
Has a value of 0.055061179
X6=723
X7=V01_A+V01_B*X6 (value of 40.69911012)
X8=1
X9=X7*X8 (value of 40.69911012)
X10=1
X11=X9*X10 (value of 40.69911012)
X13==CONCATENATE(X12,", ",X11)
The final results of X13 are:
V01, 1162, 40.6991101223582
I want them to be:
V01, 1162, 40.7
I'm trying to figure out how to make this happen. I've already tried changing the cell formatting on all of these cells (including the final cell) to one decimal palce and that didn't work.
Cell formatting and the actual number in the cell are two different things.
The cell formatting merely changes how the number is shown to you in the cell.
The actual number in the cell will still keep all precision of the number.
If you wish to have the last number rounded, consider this:
X13=CONCATENATE(X12,", ",ROUND(X11,1))
This will round the result in X11 to 1 decimal place before concatenating.
By concatenating you are changing your data to text instead of a number and the number formats won't effect it. Generally you have two options
Either round within you concatenate function
X13==CONCATENATE(X12,", ",roound(X11,1))
or change it back to a number (easiest way is multiply by 1): Note this won't work in your case since you are joining text strings and variables but is useful to be aware of.
X13==CONCATENATE(X12,", ",X11)*1
and then you can format based on decimal places.

Meaning of two minus signs together ("double unary")

What does the two - sign mean at the beginning of a formula?
Ex:
This formula gets a string date and converts it into an Excel date serial number:
=--(MID(S2,4,3)&LEFT(S2,3)&MID(S2,7,4))
The formula works fine, I just want to understand the -- in the formula.
#JNevill's Comment seems a good answer to me but for the sake of an Answer consider Y in A1 and Y in B1. This formula:
=(A1=B1)
returns TRUE. As mentioned, stick an operator in front (with 0+, or 1*) and the Boolean is turned into 1, or 0 if B1 (only) is changed to, say, X.
The single minus negates that. 0-, or -1*, at the front returns -1 for both A1 and B1 equal to Y. Negate that and the -1 result becomes 1, say with =--1*(A1=B1).
But then multiplying by one (or adding zero) is pointless, might as well just go for:
=--(A1=B1)
Note that because of the order in which the evaluations take place, the above is not the same as:
=--A1=B1
which has no meaning so returns #VALUE!.
Text functions (MID and LEFT in your example) return strings, so constructing a date index for today for example (42311 in the 1900 date system) with such functions (alone) returns five characters Excel does not recognise as possibly representing a date. Converted to numeric format and represented as a date this should look like 'today'.
So format a cell as Text and enter 42311, then reformat as Date and the result is still 42311. Format a cell as General and enter:
=--("42"&"311")
before then formatting as Date and you should see something that looks like 'today'.

Excel 2007 Duplicate Check Wrongly Converting Hex as Exponent

I have a spreadsheet used to verify a long list of 8-digit hexadecimal numbers for duplicates.
It has two columns - one for the hexadecimal values and another where the following formula is used to check for duplicates (given that this second column is column B):
=COUNTIF($B:$B, B1)
This has worked fine for most numbers except for these values:
69000700 and 690007E2.
The first column is formatted as text, however it seems that the COUNTIF function is doing some kind of unwanted implicit cast of my hex value, and taking the second hex value as an exponent (which would make it the same as the first value).
It also doesn't seem to matter what format my hex column is - the COUNTIF function always interprets these values as numbers and therefore they appear as duplicates.
Is there a way to ensure the COUNTIF function takes these cell values as string parameters without doing an implicit cast?
Maybe it's feasible to add an extra column with a formula
=CHAR(34) & B1 & CHAR(34)
copied down.
The formula encloses the text into quotes, and "690007E2" will no longer be interpreted as "69000700" (Excel 2003).

Resources