Reverse order of number pairs and then subtract them - excel

I have this text in an Excel cell in column A: 2 / 12 and want to make this subtraction in another cell in column B: =12-2.
For example, values in column A are:
2 /12
3 / 10
0 / l8
0 / 0
and I want to do this subtraction in column B:
= 12-2
= 10-3
= 18-0
= 0-0
I want to appear only the results ex. 10, 7, 18, 0
How can I do this for multiple cells?

Please try:
=RIGHT(A1,FIND("/",A1))-LEFT(A1,2)
copied down to suit.

Excel has built in Text to columns feature that would probably be useful in this case.
Under data
click Text to columns
selected Delimited
Click Next
Under Delimiters in "Other" enter "/" (without parenthesis) click finish.
That should give you 2 separate columns with your values you should then be able to easily subtract them in an adjacent cell.

This is a little weird for an excel file. I am going to make an assumption that your data in column A is formatted as "Text" because otherwise it would be calculating the value. I also assumed that there is a space between the numbers and the /. So with those assumptions in mind you could have this function in column B to get your result.
This example is for Row 1 of course but you simply copy down for the other rows accordingly
=(RIGHT(A1,LEN(A1)-FIND("/",A1)))-(LEFT(A1,FIND("/",A1)-1))

Related

In Excel, how do I get an unknown number of values from cells using a list from another cell?

I have a spreadsheet (Gantt chart) with dates in a column. Refer to the table below. The "Row" column is the row number in Excel, not a real column.
Row
Depends on Row(s) (Col F)
Start (Col G)
End (Col H)
Notes
9
7/24/21
7/26/21
10
9
7/27/21
7/30/21
Starts 1 day after row 9 ends.
11
7/25/21
7/27/21
12
9,11
7/28/21
7/29/21
Starts 1 day after MAX(row 9 end, row 11 end).
How do I automatically set cells "Start10" and "Start12" to read from cell "DependsOnRows" in their row to get the max of any numbers in the "DependsOnRows" column using a formula or other method?
Currently, I'm using this formula in cells "Start10" and "Start12", which includes a manually typed "max" function:
Start10:
=WORKDAY(MAX(H9), 1, Holidays!A$2:A$99)
Start12:
=WORKDAY(MAX(H9,H11), 1, Holidays!A$2:A$99)
I want to automate the reading of the row numbers inside the max function so they are read from the "DependsOnRows" column.
I can use any format in the "DependsOnRows" column. I can use braces, brackets, commas, spaces, whatever. The list just ideally needs to be in 1 cell, not multiple.
You can use the FILTERXML function to change the string of row numbers into a dynamic array. From there, you can INDEX the position of each row along with a fixed column number (in this case 8, or column H) to get test values for the MAX function.
Something like the below works for me:
=WORKDAY(MAX(
INDEX($A$1:$I$13,
FILTERXML("<t><s>" &SUBSTITUTE($F13, ",", "</s><s>")&"</s></t>", "//s"),8)),
1, Holidays!A$2:A$99)

Reference cells with no gaps to fill table with gaps

I have included 2 tables below to illustrate my problem.
Table 1
Table 2
I am trying to find a formula that fills rows 140, 143 & 146 (Table 2) from rows 15,16 & 17 (Table 1). There is over 100 so it is quite time consuming to input =B15 etc over and over again.
The offset method e.g. =OFFSET($B$15,(ROW()-1)*3,0) only works when I'm referencing gaps, not trying to fill them.
Essentially, where B140's formula is =B15, B143's will be =B140 + 1 row i.e. B16
Thanks for your help!
If you are trying find value for appropriate month you can use INDEX/MATCH entered as array formula:
=IFERROR(INDEX($B$1:$B$4,MATCH(TRUE,MONTH(A10)=MONTH($A$1:$A$4),0)),"")
Array formula after editing is confirmed by pressing ctrl + shift + enter
Edit
To find by month & year use:
=IFERROR(INDEX($B$1:$B$4,MATCH(1,(MONTH(A10)=MONTH($A$1:$A$4))*(YEAR(A10)=YEAR($A$1:$A$4)),0)),"")
it's also array formula
You can use modulo for this. With the Modulo function, you check if the remainder of the row you're on is divisible by a number (e.g. 3 if you want to copy a value every third row). IF(MOD(ROW(E1);3 = 0)
If that's the case, you can divide by 3 and use for example the Index function to copy the nth value of another location (or another worksheet). If that's not the case, you print "" to get an empty row.
=IF(MOD(ROW(E1);3)=0;INDEX($B$1:$B$4;ROW(E1)/3);"")
If you're working with offsets because the row numbers are not on numbers divisible by three, you could manually offset the rows (and do the same for the division that yields the index row). For example, if you want to have rows 2, 5, 8 etc:
=IF(MOD(ROW(E1)+1;3)=0;INDEX($B$1:$B$4;ROW(E2)+1/3);"")

Create Comma Separated List In Excel

I have two workbooks that I need to pull data from workbook1, to workbook2. The identifier to achieve such is empID Now for eachempID I need to show what location(s) they worked. So sample data looks like this
Workbook1
empID.....Name....Address...City...State....Zip
1
2
3
4
5
Workbook2
empID.......locationworked
1 12
2 33
1 11
4 22
3 9
1 55
5 19
2 76
1 99
I have used this formula to return the data to a different cell for each empID
=IFERROR(INDEX($B$2:$B$8, SMALL(IF($A$11=$A$2:$A$8, ROW($A$2:$A$8)-ROW($A$2)+1), ROW(1:1))),"" )
But I want to create a Comma Separated list and put everything in one cell, like so
1 11,12,55,99
2 33,76
etc
Is there a way to modify the syntax so that a comma separated list is created like in my desired output?
In workbook 2, I added this formula to column C
=IFERROR(VLOOKUP(A1,A2:$C$50,3,0)&","&B1,B1).
This assumes that your data goes as far down as row 50. Replace $C$50 with whatever row is last in your spreadsheet.
If this is a variable list, use
=INDIRECT("A2:C"&MATCH(TRUE,D:D="",0),1)
in place of the
A2:$C$50
however don't forget to use Ctrl + Shift + Enter to set the formula to an array.
Next, copy this formula down all rows. The VLOOKUP will work up the sheet. Then you can reference this list from your report sheet (I believe in this case its Sheet 1) with a VLOOKUP. it will automatically pick the first instance of each employee ID which contains the csv list.
I'd like to point out that whilst bad_neighbor's solution is quite accurate and reusable for future data changes, it is often preferable to avoid lookups where possible, and to store calculated results as values, since these aren't perfectly efficient and tend to slow down the sheet something awful given a larger quantity of data, for example when filtering / unfiltering. It's worse in older versions.
So, if this list formatting were part of a manual operation, and assuming the requirement is for each list item to be in ascending order (per the question's output), I'd do the following instead:
If workbook2's order is important, add an index of the rows (D1 := 1; D2 := D1 + 1; paste values).
Sort workbook2 by [A ascending, B descending], including index if present.
Apply this formula to column C - a fillup version of the lookup.
C1 := IF(A1=A2,C2&", "&B1,B1)
Copy-paste special values column C.
Lookup from workbook1 + copy-paste special values.
Optionally sort back according to original index (D) in workbook2.

Excel 2010 Conditional formatting. Highlings a cell if it contaons 1 of 2 conditions

I am trying to highlight a cell (or possibly the entire row) if a cell contains a value less than 0 or #N/A. Either condition would invoke a bold red text with default background color (white).
Columns are:
Column A Column K Column L Column M Column N Column O
File 1 File 1 File 2 Miles File 3
Equip # Ending Odometer Ending Odometer Driven Gallons Fuel MPG
(Key) (Calculated) (Calculated)
=Kn - Ln =Mn / Nn
(Where lower case n indicates row number)
File 1 is the master file and I use VLOOKUP to include data from files 2 and 3, so File 2 Ending Odometer and File 3 Gallons Fuel may have #N/A or 0. Either calculated field may contain 0 or #N/A. If the VLOOKUP used in Columns L or N does not find a match with the value in Column A, #N/A is displayed.
I apologize if all this background information has confused anyone.
My question is how can I set a Conditional Background for values in columns L, M, N or O if the value in Ln or Mn or Nn or On is less than 0 or the value in Ln or Mn or Nn or On is #N/A.
One other thing, I know nothing about VBA or macros, so if your solution involves either, you will have to include all coding, etc.
Thank you for your assistance.
skp8122005
Disregard my comment to your question, this should do what you want. Create 4 new conditional formatting rules and select the "Use a formula to determine which cells to format" options. Use the following formulas:
=IF(ISERROR($L1),TRUE,IF($L1<0,TRUE))
=IF(ISERROR($M1),TRUE,IF($M1<0,TRUE))
=IF(ISERROR($N1),TRUE,IF($N1<0,TRUE))
=IF(ISERROR($O1),TRUE,IF($O1<0,TRUE))
Make them all apply to $L:$O and check the "Stop If True" box. This will highlight the entire row for you.
You can do this with a single condition, i.e.
=IF(COUNTIF($L1:$O1,NA()),1,IF(COUNTIF($L1:$O1,"<0"),1))

Looking for formula to extract specific values from a row containing numbers and blanks

I have a sheet with rows of data, with many columns. I am looking for help on a formula that will extract the sum of the smallest 3 numbers in a row based on the last 5 values entered. Note that not all the rows will have values for each column, so the first value found on each row will may be found in a different column.
To determine the sum of the smallest 3 I am using the formula =SUM(SMALL(B3:R3,{1,2,3})), Unfortunately, that formula is looking at the entire range. Again, I am looking for help that with a formula that will select only the last 5 values posted.
Here is simple example. The results for each line show the totals that should be determined. Again, it needs to look for the sum of the smallest 3 based on the last 5 posted (in the example below the range would be col. 1 thru 10, with col 10 having the latest postings).
Ex.
1.....2.....3......4......5.....6.....7.....8......9.....10...... Result
31.........44....51....36..........44...34....36....38.......106 (34+36+34)
35..31...44...40.....38...52..........42....37...............115 (37+38+40)
Hope this is understandable. I am looking for a formula solution vs a VBA macro solution because of my users. Thanks for any help!!
Now that you clarified the question, I have an answer for you. This is fairly ugly but it gets the job done. You might want to hide the columns with the intermediate results - or you could get adventurous and "nest" the expressions. This makes it really hard to understand / debug though. If there's a smarter way to do this I am always open to learning.
Assuming you have the data in columns A through J, starting in row 2, put the following in cell L2:P2:
=MATCH(9999, A2:J2,1)
=MATCH(9999,OFFSET($A2,0,0, 1, L2-1)) ... copy this by dragging right to the next 2 columns
=MATCH(9999,OFFSET($A2,0,0, 1, M2-1))
=MATCH(9999,OFFSET($A2,0,0, 1, N2-1))
=MATCH(9999,OFFSET($A2,0,0, 1, O2-1))
The first line finds the last cell with data in it; the next ones find the last cell "not including the last cell", and so they work backwards. The result is a number corresponding to the columns with data. For your example, this gives
10 9 8 7 5
9 8 6 5 4
Now we want to find the sum of the smallest 3 of these: put the following equation in cell Q2:
=SUM(SMALL(INDIRECT("RC["&P2-17&"]:RC["&L2-17&"]",FALSE),{1,2,3}))
Working from the inside out:
RC["&P2-17"] results in RC[-12], which is "the cell 12 to the left of this one".
That is the first of the "last five cells with data", cell E2
RC["&L2-17"] results in RC[-7], the last cell with data in this row
FALSE use "RC" rather than "A1" indexing
INDIRECT turn string into an address (in this case a range)
SMALL find the 3 smallest values in this range
SUM and add them together.
This formula did indeed give me 106, 115 for the example you provided.
I would hide columns L through P so you only see the result (and not the intermediate stuff).

Resources