I want range for specific value in excel - excel

I want range for specific value in excel as,
my values
1
2
3
4
5
6
7
8
9
10
and suppose compare value is 2.5. If 2.5 is value then it should return range 2 and 3 in separate row for further calculations. Similarly i input value is 5.2 then it should return range 5 and 6 in separate row for further calculations

Cell E6 is the place where you have enter the value
=IFERROR((--LEFT(E6,1))&"-"&(--LEFT(E6,1)+1),"0-0")
if entered value is 5.5 the output will be 5-6

Related

Max of prior n cells truncating to first row

Say I have 1000 rows and 1 column (e.g. A1:A1000) of data. I want to define a column in a new column B such that it contains the maximum value of n prior cells (e.g. 5) in A including current row.
The part I'm having trouble with is defining the cell range such that it doesn't produce a #REF! error at first rows (first 4 rows in this example).
So as a simple example
A B
1 3.0 3.0 #REF!
2 1.1 3.0 #REF!
3 0 3.0 #REF!
4 2.5 3.0 #REF!
5 2 3.0 =MAX(A1:A5)
6 1 2.5 =MAX(A2:A6)
7 4 4 =MAX(A3:A7)
...
I tried for any 'B' cell "=MAX(A3:A7)" (in row 7) but when I copy it to cell 2 for example it displays a REF error (probably because the range went off the top).
I don't want to have to manual enter the truncated ranges in the first rows - in actuality there'd be 100s.
With INDEX and some math:
=MAX(A1:INDEX(A:A,MAX(ROW()-4,1)))

Excel formula to return last xth numeric value from row

I have a data set like this:
a 1 2 3 5 6 7
b 5 1 3 4
c 7 4 3 2 6
d 1 2 3 7
e 7 5 5 6 7
which i want to transform in excel to only show the last 4 numeric values for each row, i.e.
a 3 5 6 7
b 5 1 3 4
c 4 3 2 6
d 1 2 3 7
e 5 5 6 7
Ive managed to use =INDEX(row1,MATCH(9.99999999999999E+307,row1)) which correctly returns the last value (i.e. 7 for row1 in this case) but how could i get the 2nd last, 3rd last, 4th last etc?
With a in A1, in M1 copied across and down to suit:
=MID(RIGHT($B1&$C1&$D1&$E1&$F1&$G1&$H1&$I1&$J1,4),COLUMN()-12,1)
then hide ColumnsB:L.
(Only works for single digits, as shown. Recent versions of Excel may offer better options.)
So I managed to figure out how to do this generically for any digits:
Say your original numerical data is in cells D5:N9.
OPTIONAL:
If any of the rows of data contain the same value twice create a copy in cells D13:N17 which amends duplicates slightly by using in D13 and dragging to fill
=IF(D5="","",D5+0.0001*(COUNTIF($D5:D5,D5)-1))
Then in cells A13:A17 enter values 13,14,15,16,17
and in cells A20:A29 enter values D, E, F, G, H, I, J, K, L, M
In Cell D20 you can return the last from row 13 value using:
=LOOKUP(9.99999999E+307,D13:N13)
and copy this down for each row.
In Cell E20 you can return the 2nd last entry using
=LOOKUP(9.99999999E+307,$D13:INDIRECT(CONCATENATE(INDEX($A$20:$A$29,MATCH(D20,$D13:$N13,0)-1),$A13)))
and copy this down for each row and drag it across to H24 to fill in all the values for 3rd last, 4th last and 5th last for each row.

Finding Value In Excel Based On Highest Value and Matching Value in Excel

I have three rows in an Excel sheet that I need to get values from. Row 1 are just set numbers, Row 2 is values, and Row 3 is another value with many having the same value. I need to first check for the highest value in Row 3, match it with the value in Row 2, get the highest value in Row 2 first if Row 3 is the same, and then report Row 1 as the answer.
1 2 3 4 5 6 7 8 9 10 11 12
15 16 17 18 19 20 21 22 23 24 25 26
4 4 2 1 5 7 4 3 1 5 3 3
So I want to have it output as:
6 10 5 7 2 1 12 11 8 3 9 4
I tried a few HLOOKUP values but nothing seems to be hooking. Any ideas?
For a formula answer use this array formula:
=INDEX($A$1:$L$1,MATCH(LARGE(($A$3:$L$3*10000)+$A$2:$L$2,COLUMN(A:A)),($A$3:$L$3*10000)+$A$2:$L$2,0))
Being an array formula it must be confirmed with Ctrl-Shift-Enter instead of Enter when exiting Edit mode. If done correctly then Excel will put {} around the formula.
So enter the formula in the first cell, hit Ctrl-Shift-Enter Then drag/Copy across the number of columns desired.

Find maximum of row, return column name

I have four rows and six columns of random numbers between 1 and 10. The headers atop are named A through F accordingly. I want to populate a range (A1:A6) on another sheet with the maximum number for each row. That is easy with the MAX function. However, in a another range (B1:B6), I want to put the column name to which this number belongs.
An HLOOKUP() won't work because a maximum value in one row is likely not unique number across the entire sheet. I am thinking a MATCH INDEX type function, but my understanding of those functions, especially in conjunction, is poor.
A B C D E F
1 0 2 10 9 8
9 3 7 6 9 10
10 3 0 2 1 4
9 4 7 8 6 3
Assuming your array is in Sheet1 and the columns are labelled, please try in another sheet, copied down to suit (to Row4 since there are only four rows of numbers in your data):
=INDEX(Sheet1!A$1:F$1,MATCH(MAX(Sheet1!A2:F2),Sheet1!A2:F2,0))
This will return only the first column label from a row where the maximum for that row occurs more than once.

Sum only visibile cells using SUBTOTAL in Excel

I'm intending to get the current balance of a stock using an Excel sheet. In this workbook, the balance is entered every day. However only the most recent day's balance is actually shown, all other are hidden. The data is entered in columns, and hence only one column of data is shown.
In this example, I want to sum the values from row 21 to 24. I enter the formula from the first documented balance, to some columns ahead in time (so the range does not need to be changed often).
For this I use:
=SUBTOTAL(109,C21:O24)
The last column's values sums to 20. However, using this formula sums to 260. It actually sums all values in row 21 to 24!
I confered the site https://support.office.com/en-us/article/SUBTOTAL-function-7b027003-f060-4ade-9040-e478765b9939 where it says that the value "109" should be used as the first argument in order to only sum non-hidden values. But evidently, this does not work. I also tried to use "9" as the first argument as well with the same result.
What is it that I am missing? Why doesn't this formula execute as intended?
MCVE (I reckon that if this is copied into cell A20, the value should become 260. When hiding all columns but A,B and O should give 20 using SUBTOTAL, but for me it still produces 260).
Stock
Prod1 5 5 5 5 5 5 5 5 5 5 5 5 5
Prod2 5 5 5 5 5 5 5 5 5 5 5 5 5
Prod3 5 5 5 5 5 5 5 5 5 5 5 5 5
Prod4 5 5 5 5 5 5 5 5 5 5 5 5 5 =SUBTOTAL(109;C21:O24)
Regards
From the documentation:
For the function_num constants from 1 to 11, the SUBTOTAL function includes the values of rows hidden by the Hide Rows command under the Hide & Unhide submenu of the Format command in the Cells group on the Home tab in the Excel desktop application. Use these constants when you want to subtotal hidden and nonhidden numbers in a list. For the function_Num constants from 101 to 111, the SUBTOTAL function ignores values of rows hidden by the Hide Rows command. Use these constants when you want to subtotal only nonhidden numbers in a list.
So that can't be used to sum cells hidden by columns.

Resources