I have a time sheet and I need to calculate the difference between two time values. As this sheet will be made available to all employees, I cannot make use of the 1904 date system hence I resolved to using this
=IF(A1-B1<0, "-" & TEXT(ABS(A1-B1),"hh:mm"), A1-B1)
This works and gives a negative sign to the negative values thereby overcoming the hashes ####### problem and display in Excel 2007 and higher.
Yet I cannot create conditional formatting to the result as it is obvious that the values are interpreted as text and neither can I count a group of these values with a simple summation.
Edit 1
AFAIK there is no really good way to do this in Excel. The best I have found if you want to keep the numeric time value and can't use 1904 dates is to use a custom number format like the following:
hh:mm;-[m]" mins"
This displays positive times normally and negative times as a number of minutes. So +1:45 will display as 01:45 and -1:45 will display as -105 mins. Or for consistency you could just go for:
[m]" mins"
Which formats everything as minutes.
This works because the "elapsed time" formats ([h], [m], and [s]) do handle negative times. Unfortunately you can't have more than one in a format, and [h]:mm just triggers the hash signs again.
You could use conditional formatting.
For your formula:
C1: =ABS(A1-B1)
For your Conditional Formatting formula:
=A1<B1
If you also want to have a negative sign (or parentheses) around the value, you can also go to the Number tab of the conditional formatting format dialog box, and enter an appropriate string in the positive number field.
Be careful as the values in Column C will always be positive, so do not use them in subsequent calculations. Use the original values in A1:B1 to determine whether to add or subtract
Related
I want to count the number of times a task needs to occur within 14 days (today is 9/1). But I need to extract the date from strings of text. The formula below returns a spill error instead of one overall count.
Id also like to filter for just selected items (ex: bananas, apples, oranges). When i add that test it says all results are true.
I have conditionally formatted each cell's font to be red when the test is met but I can't count using conditional formatting. I also tried a user defined function in VBA but that can't use conditional formatting either.
=IF(OR(A5:A22="Bananas",A5:A22="Oranges",A5:A22="Apples"),(COUNTIF(B5:B22,(TODAY()-RIGHT(B5:B22,LEN(B5:B22)-FIND(" ",B5:B22)-0))<-14))
sample layout
with corrections in comments.. still not complete
Screenshots/here refer:
=SUM(1*(1=--ISNUMBER(MATCH(B3:B11,F3:F4,0)*(TODAY()-RIGHT($C$3:$C$11,LEN($C$3:$C$11)-FIND(" ",$C$3:$C$11)-0)>-14))))
Notes:
Have not paid much attention to the date component as you seem fine with that aspect (to customise illustrative e.g. I've used, replace the last part of equation above i.e. (9-MID(C3:C11,SEARCH("/",C3:C11)+1,LEN(C3:C11))>=-14) with the condition you've applied - i.e. (TODAY()-RIGHT($B$5:$B$22,LEN($B$5:$B$22)-FIND(" ",$B$5:$B$22)-0)>-14)
Suggests equation cell H3 becomes: SUM(1*(1=--ISNUMBER(MATCH(B3:B11,F3:F4,0)*(TODAY()-RIGHT($C$3:$C$11,LEN($C$3:$C$11)-FIND(" ",$C$3:$C$11)-0)>-14)))) (allowing for different ranges I use for this e.g.)
Alternative approach might be wrapping suitable function around the conditional formatting eqn. you provided in Q
RE: (pt. 3) - toying with idea of countifs, but personally prefer sum(1*(binary outcome)) 'wrapper' ☺
I have a string of consecutive dates in an excel table that represent when items were picked up from a store. I need to determine either if any gap is more than 60 days or the greatest gap. Example:
9/5/18, 9/18/19, 11/20/18, 12/21/18
The gap between the 2nd and third dates is the greatest at 63. I either need the "63" or a "yes" if >63. I have a few hundred rows of these dates so looking for a formula without the need to build helper tables.
Thanks in advance.
IF the dates are in different cells:
=MAX(B1:D1-A1:C1)>60
Depending on one's version this may need to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.
If they are in the same cell, comma delimited:
=MAX(FILTERXML("<a><b>"&SUBSTITUTE(A1,",","</b><b>")&"</b></a>","//b["&ROW($ZZ$2:INDEX($ZZ:$ZZ,LEN(A1)-LEN(SUBSTITUTE(A1,",",""))+1))&"]")-FILTERXML("<a><b>"&SUBSTITUTE(A1,",","</b><b>")&"</b></a>","//b["&ROW($ZZ$1:INDEX($ZZ:$ZZ,LEN(A1)-LEN(SUBSTITUTE(A1,",",""))))&"]"))>60
Depending on one's version this may need to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.
If the dates are all in a single cell, and you have a recent version of Excel with the SEQUENCE function, you can use:
=AGGREGATE( 14,6,DATEVALUE(TRIM(MID(SUBSTITUTE(A1,",",REPT(" ",99)),SEQUENCE(10)*99,99)))-DATEVALUE(TRIM(MID(SUBSTITUTE(A1,",",REPT(" ",99)),IF(SEQUENCE(10)=1,1,(SEQUENCE(10)-1)*99),99))),1)
where the 10 argument for SEQUENCE is just some value greater than the total possible number of included entries.
If you do not have the SEQUENCE function, you can use something like:
=ROW(INDEX($A:$A,1,1):INDEX($A:$A,255,1))
I prefer to make that a named formula, and name it seq, so the final formula would look like:
=AGGREGATE( 14,6,DATEVALUE(TRIM(MID(SUBSTITUTE(A3,",",REPT(" ",99)),seq*99,99)))-DATEVALUE(TRIM(MID(SUBSTITUTE(A3,",",REPT(" ",99)),IF(seq=1,1,(seq-1)*99),99))),1)
Date-Times in excel are in days since the epoch, floating point, with a presentation number format that you can adjust (I like YYYY-MM-DD iso date). It should be easy to convert your strings to dates, if they are not already dates by automatic conversion. I bet there is a function for that! Subtract them, but since the are date-time floating point numbers with fractions, you might need to find a function named int or integer to scrape off any fraction. Of course, if they all lack time components, that part defaults to the same time, so the subtraction returns whole days.
How do I put a formula in a Custom Number Format in Excel? For example (random example for illustration purposes),
Assume I have the following data:
INPUT
OUTPUT
Without editing the actual data in the cells, I would like to display the value in the cell divided by 2, and with two decimal places:
Is there a way to do this directly in the Custom Number Format, i.e. Without adding helper columns/cells doing the division calculation. NB. the part that has me stumped is doing the division calculation in the Number Format
Thanks!
The answer is NO, if you want to do it through custom format in a cell directly.
However, there is workaround in pivot table using calculated field option as shown below:
By the way I am curious why you want to show the number in a value other than its true value in a cell? This is not a good practice which could lead to misuse of the data in my humble opinion.
I have been wanting to display my min/60 as minutes, but the decimal is necessary for calculations. The best way I've found so far is to use conditional formatting in fractions.
0/60 "min" would display. 21666666 as 13/60 min
Which is what the cell formula was. It's only useful for around an hours worth of time, but if I come up with something to more clearly display a calculation of such as 8.5hrs as 8hrs 30min I'll update.
I need to operate on values greater than 9999:59 (up until 20000:00) in Excel. I used [h]:mm format but it seems it is not possible to do operation (like summation of two column) for values greater than 9999:59.
I already have the data so it's not possible for me to write it in another format.
I tried other formats such as [hhhhhh]:mm and [HH]:MM which my colleagues told me but they didn't work too.
Is there any way to do this?
You can certainly operate on time values > 9999:59:59
But you cannot directly enter values greater than 9999:59:59 into a worksheet cell:
From Excel Specifications and Limits:
Largest amount of time that can be entered: 9999:59:59
The reason for your #VALUE! error in I3 is because, when you entered 1000:12 into H3, since it is greater than the amount that can be directly entered, Excel has changed it to a text string.
But see this:
The formula:
H3: =H2+TIME(0,13,0)
If you must work with directly entered times greater than 9999:59:59, then you can enter that time differently in some other column, and use a formula to convert it:
For example, enter the time as a decimal number, where the decimal represents the minutes (be sure to use leading zero's for minutes < 10. eg 1 minute = 0.01)
F4: 10000.12 10000 hours 12 minutes
H4: =DOLLARDE(F4,60)/24
I need to convert from 12 hour time to 24 hour time in excel.
I have it on this format:
11/13/2016 7:00:02 AM
I need it to be like this
11.13.2016 07:00:02
How could this be done? I have approximately 1000 cells that need to be converted.
Fully agree with Teylyn - however you may want to change the display and perhaps this is what you actually meant by "conversion". To adapt the display, let's we start with this:
Select the whole range you want to display differently and you can choose from the dropdown "More number format":
Then you can go to "Custom" on the list in the left & select something like this one:
Which gives this:
Or you can use the sample to make up a display of your own (you can edit the format line to yield anything you want).
Edit: if you like the answer, please accept it.
Dates and times are stored as numbers in Excel. How these numbers show in worksheet cells is governed by formatting. If your data contains real date/time values, you don't need to convert anything.
Use formatting to display values in a different time format in the worksheet cells. The date/time will show in the formula bar according to your computer's system settings for date/time display, but that's only in the formula bar.
Use the underlying values unchanged for calculations.