I am Trying to change the Excel cells which contain hours and minutes with "h" and "m" into minutes only. The Problem here that the letters h & m are in the cell.
What i need it to look like:
2h 30m --> 150
4h --> 240
51m --> 51
Please help me out. thanks in advance.. !!
Try:
Formula in B1:
=1440*TEXTAFTER(":0:"&SUBSTITUTE(SUBSTITUTE(A1,"m",""),"h",":"),":",-2)
You could try something like this:
=IF(ISNUMBER(SEARCH("h";A1));VALUE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1;" ";"");"h";":");"m";""))*24*60;VALUE(SUBSTITUTE(A1;"m";"")))
Notice there is an IF to separate cases when there is only minutes from cases when there is also hours (calculus is different)
So find the "h" to get the hours like so:
=left(A2,find("h",A2,1)-1)
Then multiply the result by 60 (as 60 minutes in an hour)
For minutes:
=mid(A2,find("h",a2,1)+1,2)
This assumes that minutes is double digit as per your example, you could make it more precise by finding the position of the "m" and calculating the difference.
Then sum the result to get minutes.
Another legacy formula:-
=1440*SUBSTITUTE(SUBSTITUTE(IF(COUNTIF(A1,"*h*"),"","0h")&A1,"h",":"),"m","")
Related
There was an question placed before and it got the answer:
Thanks for that.
"Right now I have formatted my cell with:
h "hours" m "minutes"
So if my cell has 7:00, it displays as 7 hours 0 minutes. Is there a way to remove the hours or the minutes if these are zero? Something like 7 hours, or 0:30 as 30 minutes"
The answer was:
If you have Excel 2007 or later versions (but apparently not Excel for Mac 2011) you can achieve this with a combination of regular formatting and conditional formatting.
Assuming data in A1 down use a regular custom format like this
[<0.0415][m]" minutes";h "hours" m "minutes"
That will give you the same as your previous formatting except that any value < 01:00 will display like
30 minutes
Now you can add a conditional formatting condition. With column A selected do this
Conditional Formatting > New Rule > Use a formula to determine which cells to format > type this formula in the box
=MINUTE(A1)=0
Click the "format" button and set the following number format
h" hours"
Now if you have 16:00 in A1 that will display as just 16 hours
[conditional formatting rules will always supersede regular formatting]
But I wonder if it is possible in addition to this add time format in a way like if I have 1 hour it shows "1 hour" (in singular) instead of "1 hours"?
This should do this trick
Add this to Custom type box
[<0.0415][m] "minutes";[<0.083][h] "hour" m "minutes";[h] "hours" m "minutes"
inputs/outputs
inputs -
00:05:00
00:30:00
01:05:00
01:30:00
02:30:00
outputs -
5 minutes
30 minutes
1 hour 5 minutes
1 hour 30 minutes
2 hours 30 minutes
Notes
By putting the square bracket around [h] it will allow for more than 24 hours to be added e.g. 31 hours 30 minutes.
In Excel 1 minute is equal to 0.00069444 (1/1440 of a day). Knowing this helps to calculate the two less-then numbers.
Alternative option
If you just want h rather than hour and m rather than minutes try this
[<0.0415][mm] "m";[h] "h" mm "m"
=IF(HOUR(B9)<>0,HOUR(B9)&" hour"&IF(HOUR(B9)<>1,"s "," "),"")&IF(MINUTE(B9)<>0,MINUTE(B9)&" minute"&IF(MINUTE(B9)<>1,"s",""),"")
TLDR : extract every values manually > then put if conditions for 0,1 and other > print value..
Hope it helps.
I have formula to separate hours and minutes by comma.
=CEILING(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(P96;"s";"");" min";"");" hour ";",");0,1)
This works for 4 hours 40 mins and 1 hour 10 mins. However there might case like 20 mins. Then my formula is displaying 20 that is not correct and should be 0,2. Any suggestions how to fix this issue?
Note! Values like 4 hours 40 mins are in one cell, in this case in cell P96. Information comes straight from Google Maps xml.
=CEILING(IF(ISNUMBER(SEARCH("hour";P96));SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(P96;"s";"");" min";"");" hour ";",");"0,"&SUBSTITUTE(SUBSTITUTE(P96;"s";"");" min";""));0,1)
Conditionally add a dummy prefix that satisfies the hours substitution.
=CEILING(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(IF(ISERROR(SEARCH("hour"; P96)); "0 hours "; "")&P96;"s";"");" min";"");" hour ";",");0,1)
Type your time in cell A1. As an example, you could type "2:30", "14:30" or "2:30 PM".
Type "=HOUR(A1)" in cell A2 to produce only the hour. As an example, extracting the hour "2:30 PM" would give you "14," because 2 PM is the fourteenth hour in the day.
Type "=MINUTE(A1)" in cell A3 to extract the minutes.
Type "=SECOND(A1)" in cell A4 to extract the seconds.
Data is:
A1 = 29. B1 = 30. C1 = 2.
D1 = TIME(A1, B1, C1).
How can I get D1 to return 29:30:02?
Formatting the D1 cell to [hh]:mm:ss does NOT work!
If I ran for 29 hours in a month, Excel thinks I ran for only 5 hours.
Thank you.
Edit: Thank you!! I got it!!! D1 = TIME(A1, B1, C1) + INT(A1 / 24)
The result you get is exactly how TIME function works:
Hour Required. A number from 0 (zero) to 32767 representing the
hour. Any value greater than 23 will be divided by 24 and the
remainder will be treated as the hour value. For example, TIME(27,0,0)
= TIME(3,0,0) = .125 or 3:00 AM.
You could do
=A1/24+B1/24/60+C1/24/60/60 in D1
Then the resulting value formatted as [hh]:mm:ss will show 29:30:02.
That is because 1 is 1 day in Excel. So 1/24 is 1 hour, 1/24/60 is 1 minute and 1/24/60/60 is 1 second.
Time is trying to give you clock time so 29hrs=5am.
So if you want that result how about just:
D1=CONCATENATE(A1,":",B1,":",C1)
If then you want the 02 you would have to interject a little formatting to those columns...
Very similar solution as given above by Axel Richter is shown in support article Add or subtract time by Microsoft.
Basically it boils down to using custom format of [h]:mm;#. However I am not sure, what the exact difference to [hh]:mm:ss (or more precisely to [hh]:mm) is - if at all? A quick check in Excel did not reveal any differences to me.
However, as the support article covers topic of adding and subtracting of time values pretty comprehensively, I hope it will be useful to be cited here.
I'm using a time-tracking sheet that calculates the time spent on a job by doing a simple subtraction between a start time and an end time in two cells.
The hh:mm format would suffice in this case, or as a small modification I'm using [h] "h" mm "m", but the issue with both is that I do not want the hours to display when there are none (when hours = 0).
If for example 35 minutes are logged I would like the output to be 35 m and not 0 h 35 m. The [mm] format might be an option then, but I would still like my time above 60 minutes to be displayed as 1 h 30 m, and not 90 m.
Please try:
[<0.04166666][mm] "m";[h] "h" mm "m"
Not at all elegant, but how about this:
=IF(HOUR(time)<1,MINUTE(time)&"m",HOUR(time)&"h "&MINUTE(time)&"m")
Returns a cell value 02:24:00 as "2h 24m"
and a cell value 00:14:24 as "14m"
I am trying to report "Number of Elapsed Seconds" in these breaks: Less than 15 minutes, 15 to 19 min, 20 to 24 min, 25 to 29 min, 30 to 45 min, 45 to 60 min, and 60 min or more.
I have a field that shows elapsed seconds and I am able to get the breaks I want -- In Total -- by using the following formula:
=SUMPRODUCT((ABS(TestTable!$AF$2:$AF$50)>=0)*(ABS(TestTable!$AF$2:$AF$)<=899))
(where 'TestTable' is the sheet where the data is located and Col AF is where elapsed seconds is stored). The problem?
I need to cut each break down by another field. Also in 'TestTable' is a field with either PRODx or PRODz in it (it's Col H).
So I need to say "If Col H = PRODx, then count how many records are less than 15 min and put it in a certain cell ---THEN--- if Col H = PRODz then count how many records are less than 15 min and put that result in a different cell".
Anybody know a way to write this?
if you have excel 2007 or later, COUNTIFS should work out for you.
=COUNIFS(H:H,AF:AF,"<900",H:H,"PRODx") for less than 15 mins, and PRODx
=COUNIFS(H:H,AF:AF,"<900",H:H,"PRODz") for less than 15 mins, and PRODz
then for the ranges you expand the selection
=COUNIFS(H:H,AF:AF,">=900",AF:AF,"<1200",H:H,"PRODx") for 15-19 mins, and PRODx
=COUNIFS(H:H,AF:AF,">=900",AF:AF,"<1200",H:H,"PRODz") for 15-19 mins, and PRODz
keep repeating this for all the ranges of time/PRODs that you need
In cell A1, type:
=COUNT(IF(H:H="PRODx",IF(AF:AF="Less Than 15 Seconds",M1:M5)))
M is just another random column
In cell A2, type the same, but change PRODx to PRODz.
Make sure to enter all formulas as an array formula, by hitting CTRL + SHIFT + ENTER after typing, instead of just enter.
See this link for more: Count If WIth Multiple Criteria
EDIT
If you must have a VBA solution, let me know. Otherwise, you don't need VBA. Also, if you are running Excel 2007 or above, you can use the CountIfs function, which will be cleaner and less resource intensive than the Array formula above.