How to display start and end times in one cell in excel? - excel

I have a schedule for work that lists employees shifts as durations, i.e. 11-7, 1030-6, etc. within a single cell. If these were single times like 6, 1130, etc, I could convert to time format easily, but how can I make these cells display the shift start and end time in time format?
The goal is to have excel use these times to sort and filter the corresponding employees on another sheet according to their scheduled shift. Is there a way to display "hh:mm-hh:mm" to represent a shift in one cell?

This is possible using formulas, but you have to be specific about formats and testing the entries.
The primary piece of the formula to understand is how to separate the time "values" on either side of the "-". This solution assumes that a dash ("-") will ALWAYS be present in the cell. For the shift entry "2-11" (assume this is in cell A2), you can use a combination of FIND, LEFT, and RIGHT to separate all the characters on either side of the "-" using these formulas
Cell A2 contains "2-11"
LEFT(A2,FIND("-",A2)-1 returns "2"
RIGHT(A2,LEN(A2)-FIND("-",A2)) returns "11"
IMPORTANT: these formulas now become "the time value" and will be repeated inside a larger formula.
From here on out, it's a matter of reformatting the string into a time-formatted string by adding a colon ":" at the appropriate place in the string in order to create an Excel time value.
Helper columns are used to get all the values cleanly, as shown in this example:
Formula in B2: =IF(LEN(LEFT(A2,FIND("-",A2)-1))<=2,TIMEVALUE(LEFT(A2,FIND("-",A2)-1)&":00"),TIMEVALUE(LEFT(A2,FIND("-",A2)-3)&":"&RIGHT(LEFT(A2,FIND("-",A2)-1),2)))
Formula in C2:
=TIMEVALUE(IF(LEN(RIGHT(A2,LEN(A2)-FIND("-",A2)))<=2,RIGHT(A2,LEN(A2)-FIND("-",A2))&":00",LEFT(RIGHT(A2,LEN(A2)-FIND("-",A2)),LEN(RIGHT(A2,LEN(A2)-FIND("-",A2)))-2)&":"&RIGHT(RIGHT(A2,LEN(A2)-FIND("-",A2)),2)))
Formula in D2: =IF(C2>B2,C2,C2+TIME(12,0,0))
Formula in E2: =(D2-B2)*24
Formula in F2: =TEXT(B2,"hh:mm")&" - "&TEXT(D2,"hh:mm")

Related

Is there a way to add a formula to unique data points in excel?

I am trying to clean some data with this format:
A1 B1 C1
"0,1,0,E,1" "0,0,0,E" "0,1,1,1,2,E"
To obtain the information, I will need to sum up each cell individually, and then calculate the sum over a row.
So far, I have replaced all of the "E"s (for empty) with no data, which removed the E's, and I have replaced all of the commas with "+" signs to add the numbers in the cell. To run the formula of each cell, I will need to now place an "=" in front of each text string, however, if I copy it in with something like "="="&A1" the formula will not run because excel is reading the = as a letter or symbol and not an operator. Do you know of a way to fix this problem?
Thank you so much!
I think this will work for your version ...
=SUM(FILTERXML("<d><c>" & SUBSTITUTE(A1,",","</c><c>") & "</c></d>","//c"))
That's applied like below ...
... there's always someone smarter than me but that seems to work.
It’s not an in place replacement but it keeps your source data intact and provides a nice reconciliation point.
Using a separate sheet for each column of values, given data in cell A1 of
0,0,0,1,0,1,1,E,1,0
In C1, enter the formula
=IFERROR(MID(SUBSTITUTE(SUBSTITUTE($E$14,",",""),"E",""),COLUMN()-2,1)*1, "")
and drag the fill handle to to the right for as many cells as the longest number of data points you have.
Enter your SUM()formula in B1 (you can use the shortcut ALT + =).
Have you tried something like this, please refer the image, where its showing as per your required output, three alternative formulas
1.) Formula used in cell B2
=SUMPRODUCT(IFERROR(--MID($A2,ROW(INDIRECT("1:"&LEN($A2))),1),0))
2.) Formula used in cell D2
=SUMPRODUCT(IFERROR(--MID($C2,SEQUENCE(LEN($C2)),1),0))
The 2nd formula is applicable to Excel 2021 & O365 Users only
3.) Formula used in cell F2
=SUM(IFERROR(--MID($E2,ROW($1:$1000),1),0))
This is an array formula, so requires to press CTRL SHIFT ENTER !
Here is an update, the last formulas, which i have shared, shall work only when the digits are less than 10, however the present formula, shall work for all number of digits,
Formula used in cell B17
=SUMPRODUCT(IFERROR(--MID(SUBSTITUTE($A17,",",REPT(" ",100)),COLUMN(A1:Z1)*99-98,100),0))
Please adjust your range accordingly as per your data.

Comparing comma separated numbers in cells

I am trying to compare the numbers in the Reachability Set column with the numbers in the same row of the Antecedent Set column and return the common values in the corresponding cells of the Intersection Set column.
Screenshot:
In Excel 2016 (but NOT Excel 2013), you can use the following array-entered formula.
=TEXTJOIN(",",TRUE,IFERROR(1/(1/(ISNUMBER(FIND(","&TRIM(MID(SUBSTITUTE(B2,",",REPT(" ",99)),seq_99,99))&",",","&A2&","))))*TRIM(MID(SUBSTITUTE(B2,",",REPT(" ",99)),seq_99,99)),""))
seq_99 is a Named Formula
Refers to: =IF(ROW(INDEX($1:$65535,1,1):INDEX($1:$65535,255,1))=1,1,(ROW(INDEX($1:$65535,1,1):INDEX($1:$65535,255,1))-1)*99)
To enter an array formula, after entering the formula in the cell, confirm by holding down ctrl + shift while hitting enter. If you do it correctly, Excel will place braces {...} around the formula.
Although you would think a VBA solution is required, it is actually quite simple to do this with formulae, provided you use a lot of helper columns. These can, of course, be hidden.
All you need is a number of columns equivalent to the maximum of the numerals in the sets, after each of the original columns of your table. For the example supplied, this would be 17 columns.
Here is a screenshot of the new table with the helper columns unhidden:
The follow formulae are entered into the top left cell of each coloured region and filled/copy-pasted/ctrl-entered into the rest of the cells.
Red Cells (entered into B2):
=IF(ISERROR(FIND(","&B$1&",",","&$A2&",")),0,1)
Green Cells (entered into T2):
=IF(ISERROR(FIND(","&T$1&",",","&$S2&",")),0,1)
Blue Cells (entered into AL2):
=IF(B2*T2,AL$1&",","")&AM2
And finally, the result entered into cell AK:
=LEFT(AL2,LEN(AL2)-1)
The formulae work by ensuring that all the numbers in the sets have a preceding, and trailing, comma so that they can be uniquely searched for.
Then it is a simple matter of constructing a grid for the sets where a 1 means the number exists in the set a 0 means it doesn't. Multiplying these two grids together results in the "intersection set".
Then it is a simple matter of reconstituting the result strings.
Caveat:
This solution won't work correctly if there are any spaces in the "Set" data. To overcome this you need to use the SUBSTITUTE() function.

How to sum several bracket-surrounded numbers of a single cell with Excel formula?

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(S‌​UBSTITUTE(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)

Excel: Index-Match using keywords and then SUM results (no VBA)

I've got a sheet with a transaction list. It includes a description of the transaction and the transaction total cost.
I'm looking for a way, without using Visual Basic, to use comma-separated keywords entered in a cell to search for all matching transactions, and then give their total value.
For example:
B4:B6 are keywords for look up.
C4 should look up in range B10:B26 for all cells containing any of the keywords in B1 (tesco OR co-op OR waitrose), and return the total value of the corresponding values in Range C10:C26. In this case it should SUM C11, C16, C21, C23, C25.
It's important to note that it shouldn't be case sensitive.
Can it be done?
You can do this with Array Functions. These functions operate similarly to "Sumifs" / "Countifs" / "Sumproduct": they perform functions normally designed to look at a specific cell, over an entire range of cells.
First let's deal with summing the total for "giffgaff" / "paypal":
In cell C5, use the following formula [As it is an Array formula, you must confirm by pressing CTRL + SHIFT + ENTER every time you edit the cell, instead of just ENTER] , and drag down to C6.
=sum(if(iserror(search(B5,$B$10:$B$26)),"",$C$10:$C26))
This looks at each row from B10:B26 (note that the entire column cannot be selected as an array formula calculates for all cells, even blank ones - so this drastically slows performance. You must specifically identify the rows you care about like this), and if there is an error when trying to search for the term in B4, that means the term does not appear on that particular row. If there is no error, it pulls the amount from column C. All of these rows are then summed together to get a single total.
Now to do the same for cell C4, you need to add in the complexity of first pulling apart each term which appears between a comma. I agree that #Tom Sharpe that you should probably do this in different cells to make it more clear what you're doing. This could be done by individually pulling terms between commas, and then having individual totals (which use the array formula above).
To do this most efficiently, I'd have use a helper column in column C, which will identify how many commas are in the text in column B, like so, in C4:
=len(B4)-len(substitute(B4,",",""))
This takes the length of B4, less the length of B4 where all commas have been replaced by blanks - giving the # of commas.
That formula can then be used to split out the words between commas, using the MID and SUBSTITUTE functions. Let me know if you need elaboration on how to do that. Once you have broken out the individual words, you can search with the Array function as above.

excel pointing to a cell when the number of the cell is calculated

how do I point to a cell when i calculate the number of the cell any time diffrently?
exemple:
='sheet1'!$F(C4+8)
In case that in C4 there is "2" then excel will read it as
='sheet1'!$F10
OR
='sheet1'!$F(Y9*8+X4:E1)
and in case of Y9=2 X4=32 E1=16
THEN excel will execute:
='sheet1'!$F18
I'd prefer to use INDEX rather than INDIRECT, i.e.
=INDEX(sheet1!$F:$F,C4+8)
You can replace C4+8 with any calculation that returns a row number
That has two advantages over INDIRECT - it isn't "volatile" and because the range isn't text it can adjust if you want to delete columns or copy across etc.
You will have to use INDIRECT():
=INDIRECT("'sheet1'!$F"&C4+8)
INDIRECT takes a text and converts it to a range. You can put formulas and other calculations inside.

Resources