change hh:mm into decimal hh.mm (see example) - excel

In cell B239, I have 37:15 which represent the total number of hours it took someone to complete a task.
In cell C239 I have the following formula
=INT(B239)*24+HOUR(B239)+ROUND(MINUTE(B239)/60,2)
which gives me 37.25 that is 37 hours and a quarter of 100. I am happy with this result and it does what I am looking for. However, in B241 I have 24:00 which should technically return 24.00 but it returns 0 in cell C241 instead.
It is as if 24:00 is recognised as midnight rather than 24 hours.
Note that the format of B239 and C239 is [h]:mm. B241 and C241 format is general.
Many thanks for your assistance
Abe

Try this:
=TEXT(B239*24,"00.00")
on 24:00 it will return 24.00
As # Darren Bartrup-Cook mentioned this will be a text field so any reference using this needs to convert it to a number. There are many ways to do this.
You can us the double negative on the result, lets assume the result of the above formula is in C239:
=--C239
But ultimately the best method to do what you want is to format the cell in which you want the value as "General" with two decimal places then the whole thing can be done with one formula:
=Round(B239 * 24,2)
This will return a number and not a text with the correct formatting.

Related

Time comparison in Excel

This should be straight-forward, I'm trying to compare if a value of time is less (or more) than another.
=IF(A1 > B1,True,False)
Where A1 and B1 are a number of hours and minutes in [h]:mm format.
A1 is 48:45 in [h]:mm format
B1 is 50:00 in [h]:mm format
If I wanted to replace B1, in the formula, with an absolute time (say of fifty hours) than I thought the answer might be either:
=IF(A1 > TEXT("50:00", "[h]:mm"),True,False)
=IF(A1 > TIME(50,00,0),True,False)
But it's not. Any ideas?
TEXT returns Text and not a number and as such it would always be greater than the time.
But we can turn it into a number by simple multiplying it by -1*-1
=A1>--TEXT("50:00", "[h]:mm")
But then the simple would also work:
=A1>--"50:00"
TIME returns the time portion and as such:
TIME(50,00,0)
resolves to 2:00 or 0.0833333 as it is the time part of the number without the integer.
So we can just do some simple math:
=A1 > 50/24
now the 50/24 will resolve properly to 2.083333
The VALUE function can come in handy for you. It's the build-in function to turn text-strings that represent a numeric value into an actual numeric value, so:
=A1>VALUE("50:00")

Excel average of values in time values

I have these values, which are time values. However, they are not formatted to time values, so an average will give me 8:82, when it should give 9:03. I can't seem to change the format into hh:mm, the values change to 00:00.
Current format is #0:\00
8:53 9:11
How do I get these recognized as time values?
Assuming that 8:53 is in A1 and 9:11 is in B1 then you can use this formula:
=TEXT(AVERAGE(TIMEVALUE(A1),TIMEVALUE(B1)),"hh:mm")
Which actually gives an average of 9:02.
The Office documentation says:
Returns the decimal number of the time represented by a text string. The decimal number is a value ranging from 0 (zero) to 0.99988426, representing the times from 0:00:00 (12:00:00 AM) to 23:59:59 (11:59:59 P.M.).
So you wouldn't be able to do something like =TEXT(AVERAGE(TIMEVALUE(A1:D1)),"hh:mm")

how to add zeros after numbers to get a fix length in EXCEL

I have 3 numbers in excel.
A1. 498
A2. 899
A3. 5209
I want the numbers as the followings:
B1. 49800
B2. 89900
B3. 52090
I am still finding the solutions via online but most of the resource is discussing about leading zeros.
Please, could you kindly give me any ideas? Thanks.
I hope this formula may be of some use:
=A1 & REPT("0"; 5 - LEN(A1))
Thought this does not set the format of the cell itself (which I doubt can be done as you are changing the value of the cell by adding the zeros)
The formula only works if you are dealing with numbers as text, so you may need to convert them to text in the formula (TEXT(A1; "0") instead of A1)
you can do this one quite easily without VBA - using an IF and the very handy REPT function:
=IF(LEN(H13)<5,H13&REPT(0,5-LEN(H13)),H13)
Essentially - if the length is less than 5 - you repeat 0 up to the amount of times that its missing.
Seems like simple math to me. Essentially you want to shift left (base 10) a certain number of times. We can do this by:
Calculate the ceiling of the base-10 logarithm of the value to get it's "length"
Subtract the result from the target "length" of 5, this is the number of places we want to shift
Take 10 to this power and multiply back by the value.
In other words, where x represents the value in column A you want to transform:
In Excel, this would be expressed as:
=A1*POWER(10,(5-CEILING(LOG10(A1),1)))

How to change a timespan into decimal format in excel?

I have the following problem. In my excel sheet, I subtracted two time values to get its timespan.
Here is an example:
16:30-8:00=8:30
the cell format is a time so its all fine. Now the problem:
I need to show the timespan also as a decimal. So the 8:30 should be a 8,50
Anybody know how to do this?
Use =24*(B2-C2), where the cell where calculation happens should be formatted in 2 decimal number format .
B2= start time.
C2= End time.
Try this
Say A3 is 08:30, you can put this in A4
=HOUR(A3) & TEXT(MINUTE(A3)/60, ".00")

SUM data according to dates in Excel

My problem is the following...
I have a little aeroplane and I need to track the hours. I have to track the hours by sectors and not the total of the day (that's why sometimes I have 2 or 3 on the same day).
Now this is the problem... On column C I need to SUM the hours of the last 7 days. And any given 7 days, not just last week. To do it manually is quite easy... the problem is that I need a formula as my records are quite large...
Here with a small example (let's say that there was NO HOURS before 15/01/2009)...
COLUMN A-------COLUMN B-------COLUMN C
DATE--------------HOURS-------HOURS LAST 7 DAYS
15/01/2009-------01:00-------01:00
15/01/2009-------02:15-------03:15
16/01/2009-------01:15-------04:30
17/01/2009-------01:30-------06:00
18/01/2009-------01:30-------07:30
18/01/2009-------01:00-------08:30
18/01/2009-------02:00-------10:30
19/01/2009-------02:30-------13:00
19/01/2009-------03:00-------16:00
20/01/2009-------////////--------16:00
21/01/2009-------01:00-------17:00
22/01/2009-------01:30-------15:15
23/01/2009-------02:00-------16:00
I've been fighting for the last weeks trying to figure out a formula but no luck... any suggestions?
Thanks
Another solution that basically does much the same as the earlier offered solutions:
In C1, enter the following formula:
{=SUM(IF(($A$1:$A1>=($A1-6))*($A$1:$A1<=$A1), $B$1:$B1, 0))}
And then just drag the formula down.
If you're not familiar with array formulas, the {} outer brackets just indicate that the formula is an array formula. To get it to execute correctly, you need to copy the part inside the {} brackets into the formula bar, and then hit Ctrl+Shift+Enter to indicate that it's an array formula.
First thing is to get the begin date, which would be the following function:
=Now() - 7
If you renamed that cell to "WeekBegin", then you could use the following formula to calculate the total hours:
=SUMIF(A:A,">=" & WeekBegin,B:B)
Notice that I used column references; this was to both simplify the formula, but also allow you to add new data to the end of the range easily. You will need to take care that your WeekBegin cell is not in that column A or column B, otherwise you'll get a circular reference warning.
If you planned to have numeric data above or below your input range, you would need to explicitly call out the sum and criteria ranges as follows:
=SUMIF(A2:A14,">=" & WeekBegin,B2:B14)
Additionally, you may find that your result comes up initially as a decimal. That's Excel's date serial format, so you may need to format your result as time.
Hope that helps!
[Edit: On second pass, if you're looking to sum a range based on a from and to date (so any 7 days as you seem to imply in your post), look for the previous poster's note, i.e.:
=SUM(B:B) - SUMIF(A:A, "<="& BeginDate, B:B) - SUMIF(A:A, ">"& EndDate, B:B)
A more elegant solution is offered in Excel 2007 using the SumIFS() function:
=SUMIFS(B:B, A:A, ">=" & FromDate,A:A, "<" & ToDate)
Note that the arguments for SUMIFS are in a different order than the standard SUMIF.
Happy Summing!]
Here's the data in better format if someone wants to try:
15-Jan-2009 01:00
15-Jan-2009 02:15
16-Jan-2009 01:15
17-Jan-2009 01:30
18-Jan-2009 01:30
18-Jan-2009 01:10
18-Jan-2009 02:00
19-Jan-2009 02:30
19-Jan-2009 03:00
20-Jan-2009
21-Jan-2009 01:00
22-Jan-2009 01:30
23-Jan-2009 02:00
I got the function:
=SUM($B$1:$B$13)-SUMIF($A$1:$A$13, "<="& (A1- 7), $B$1:$B$13) - SUMIF($A$1:$A$13, ">"& (A1), $B$1:$B$13)
This was based on Sum of named ranges conditional to date?.
The idea is to first compute the total sum: SUM($B$1:$B$13)
then subtract any values that happened older than 7 days ago: SUMIF($A$1:$A$13, "<="& (A1- 7), $B$1:$B$13)
then subtract any values that happened in the future: SUMIF($A$1:$A$13, ">"& (A1), $B$1:$B$13)
The point is to use SUMIF function, which "adds the cells specified by a given criteria."

Resources