How do I make an excel formula skip empty cells - excel

I have a spreadsheet with data in a single row. The data is arranged by year with the earliest date in the right most cell and the latest date in the far left cell.
What I need is a formula that will begin looking at the cells beginning on the right (earlier date) and move to the left toward a later date skipping the empty cells. As soon as it finds data in one of the cells I need it to stop and show the value in that cell.
I have attached a picture as an example, in that picture I need it to begin at the cell for 2003 and begin moving left ignoring empty cells until it finds a cell with data. In this case the cell for 2005 contains data. I need it to copy that value ($2.43) and place it in the cell marked earliest value.
In the pictue I manually entered 2.43 in the cell for 2005 to show what i need.!

You can use LOOKUP function to get the last value in a row, so if you have years in A1:J1 and dollar amounts in A2:J2 just use this formula to get the last numeric value from A2:J2
=LOOKUP(9.99E+307,A2:J2)
9.99E+307 is [almost] the largest value that Excel allows, when you use that "big num" as lookup value the result is the last number in the range

I made two ranges, starting E4 to J4, I place 1,2,3,4,5,6. Below (thus range: E5-J5) I placed 6,5,4,3,2,1.
In a random cell I placed this formula:
=INDEX(E5:J5,MATCH(MIN(E4:J4),E4:J4,0))
This look in E4:J4 for the number that matched MIN(E4:J4), thus the lowest number. Then selects that value, matching the index, in the range E5:J5.

As follows from your image - year should be less than 10 yr history. In that case try following formula (I suppose that your data ( years and values) are in B3:X4 range):
=HLOOKUP(MIN(IF((B4:X4<>"")*(B3:X3>YEAR(NOW())-10),B3:X3)),B3:X4,2,0)
Note, that it is an array formula, so you need to press CTRL+SHIFT+ENTER to evaluate it.
If you don't need to use condition year should be less than 10 yr history, just remove *(B3:X3>YEAR(NOW())-10) from the formula:
=HLOOKUP(MIN(IF(B4:X4<>"",B3:X3)),B3:X4,2,0)
and press CTRL+SHIFT+ENTER to evaluate it.

Related

Excel: dynamically calculate range next to a searched up cell

I am an occasional Excel user and stuck how to create a dynamic range.
After looking up a text in a table, how can I calculate the range next to this cell, up to the next empty row? Not using VBA.
Thanks for your help.
In H4, formula copied down :
=IFERROR(INDEX(INDEX(C:C,MATCH(F4,A:A,0)):C$1000,MATCH(G4,INDEX(B:B,MATCH(F4,A:A,0)):B$1000,0)),"")
Should you want a dynamic range,
Change C$1000 to INDEX(C:C,MATCH(9.9E+307,B:B)
and
Change B$1000 to INDEX(B:B,MATCH(9.9E+307,B:B))
Then
The H4 copied down formula become :
=IFERROR(INDEX(INDEX(C:C,MATCH(F4,A:A,0)):INDEX(C:C,MATCH(9.9E+307,B:B)),MATCH(G4,INDEX(B:B,MATCH(F4,A:A,0)):INDEX(B:B,MATCH(9.9E+307,B:B)),0)),"")
Edit :
As per Ron Rosenfeld's comment, "should B11 change to 24 and G4 change to 24"
The "Source Table" set up in Excel Table type for dynamic range growing purpose
and
The H4 formula change to :
=IFERROR(LOOKUP(9^9,Table1[price]/(LOOKUP(ROW(Table1[texture]),ROW(Table1[texture])/(Table1[texture]<>""),Table1[texture])=F4)/(Table1[length]=G4)),"")
Combining the Index() and Match() functions usually works well when using two conditions. However, you will need to fill out the entire column A with the "texture" list in order for the below formula to work.
=INDEX(<P1>, MATCH(TRUE, (<T1>=<T2>) + (<L1>=<L2>) > 1,0))
Where <P1> is your entire price column (ex. C2:C15)
Where <T1> is your entire texture column (ex. A2:A15)
Where <T2> is your texture lookup value cell
Where <L1> is your entire length column (ex. B2:B15)
Where <L2> is your length lookup value cell
Let's say that you input your texture value into cell F3, and your length value into cell F4. With the remaining columns remaining as they are in your image, you would use the following formula:
=INDEX(C2:C15, MATCH(TRUE, (A2:A15=F3) + (B2:B15=F4) > 1,0))
Now last time I had to use Index/Match I thought I had to place the formula into an array. However, the above seems to work without it.
If you notice that it's not working as expected, you can place into an array formula by clicking the cell that contains the formula, then clicking the formula box at the top. While in the formula box, simultaneously press Ctrl + Shift + Return. This should then place curly brackets around your entire formula if done properly, as such:
If you have O365 with the SEQUENCE function, you can use, for price:
=IF(G4="","",VLOOKUP(G4,INDEX($B:$C,SEQUENCE(MATCH(TRUE,ISBLANK(INDEX($B:$B,MATCH(F4,$A:$A,0)):INDEX(B:B,ROWS(B:B)-MATCH(F4,$A:$A,0))),0)-1,,MATCH(F4,$A:$A,0)),{1,2}),2,FALSE))
explanation:
get starting row:
MATCH(F4,$A:$A,0)
ending row will be the first blank row after the starting row:
MATCH(TRUE,ISBLANK(INDEX($B:$B,MATCH(F4,$A:$A,0)):INDEX(B:B,ROWS(B:B)-MATCH(F4,$A:$A,0))),0)
Construct the relevant array:
INDEX($B:$C,SEQUENCE(MATCH(TRUE,ISBLANK(INDEX($B:$B,MATCH(F4,$A:$A,0)):INDEX(B:B,ROWS(B:B)-MATCH(F4,$A:$A,0))),0)-1,,MATCH(F4,$A:$A,0)),{1,2})
The above might reduce (with wavy) to:
index(b:c,{9,10,11},{1,2}
Then it's just a matter of applying the VLOOKUP
A more understandable, but longer with more operations, formula available in O365 makes use of LET. The advantage is that one can use names which indicate what each section of the formula does.
For example:
=IF(G4="","",LET(startRow,MATCH(F4,$A:$A,0),numRows,MATCH(TRUE,ISBLANK(INDEX($B:$B,startRow):INDEX($B:$B,ROWS($B:$B)-startRow)),0)-1,
arr,INDEX($B:$C,SEQUENCE(numRows,,startRow),{1,2}),price,XLOOKUP(G4,INDEX(arr,0,1),INDEX(arr,0,2)),price))
Or, using VLOOKUP
=IF(G4="","",VLOOKUP(G4,LET(startRow,MATCH(F4,$A:$A,0),numRows,MATCH(TRUE,ISBLANK(INDEX($B:$B,startRow):INDEX($B:$B,ROWS($B:$B)-startRow)),0)-1,arr,INDEX($B:$C,SEQUENCE(numRows,,startRow),{1,2}),arr),2,FALSE))
Finally, for earlier versions of Excel, you can use this whopper where we replace the SEQUENCE function with a construct like: ROW(INDEX(A:A,firstRow):INDEX(A:A,lastRow))
=IF(G4="","",VLOOKUP(G4,INDEX($B:$C,ROW(INDEX($A:$A,MATCH(F4,$A:$A,0)):INDEX($A:$A,MATCH(F4,$A:$A,0)+MATCH(TRUE,INDEX($B:$B,MATCH(F4,$A:$A,0)):INDEX($B:$B,ROWS($B:$B))="",0)-2)),{1,2}),2,FALSE))

Array to lookup multiple columns and take another columns information

I am trying to lookup a part number in a separate table array, the same value could be in multiple rows. The formula should find each instance of the value in the other table, move to a date column and determine which months the value exists in and which row it belongs to. The entire table B3:F15 should be automated. I have attached an image with proper explanation of what I am trying to accomplish if at all possible.
The formulas would be entered into B3:F15. These are the cells where the data will get pulled into. Each row will search for its corresponding Part Number in column A. I.e, B3 to F3 is only looking for A3 data. The rows are used to determine if a Part number in L2:P4 matches their row value in Column A and if was used in that month belonging to months B2:F2. If the Part number was used in the corresponding month then it will output the Plant # from Column I. In some cases the Part numbers in L2:P4 can exist in multiple rows, but they are unique to each column.
As an example I have manually filled in data for PN1001 and PN1021. For PN1001, this belongs to B3:F3. Each cell in B3:F3 will search the array L2:P4 and realize it is found only once and in M4, so it will look at the dates from its row, J4 and K4, and determine which months it was used in. Since it was used in Jan, Feb, and Mar, it will output the Plant # into D3, E3, F3. In the example of PN1021 it is the same but in this case PN1021 exists in L2 and L4, so it will take the date of J2,K2, and J4,K4.
Some Part numbers can be a combination of letters and numbers, some may just be numbers.
In terms of how to build the formula I am not sure what combination of Index/Match/Lookup I should be using. My theory is that each cell in B3:F15 would include a formula that be =MATCH(Lookup(columnA with L3:P4)) (but how do you get it to lookup multiple instances??) Some research lead me to use this concept to find multiple instances and point to the row #.
SMALL(IF(Lookup Range = Lookup Value, Row(Lookup Range),Row ()-# of rows below start row of Lookup Range)
Once I can find each instance, then Index the row and compare if the cell in B3 is greater than J3 and less than K3 to determine the months which should have a value entered. IFYES, then output column I from the row number.
If you have any better solutions or ideas to perform this action then please provide feedback. Thanks in advance for the support.
I think the formula below will do what you want. I created a table out of your I1:P4 data, and used structured references, as I find it easier to follow.
B3: =IFERROR(
INDEX(partsTbl,
MAX(
($A3=partsTbl)*
(B$2>DATE(YEAR(partsTbl[[Test Start Date]:[Test Start Date]]),MONTH(partsTbl[[Test Start Date]:[Test Start Date]]),0))*
(B$2<DATE(YEAR(partsTbl[[Test Finish Date]:[Test Finish Date]]),MONTH(partsTbl[[Test Finish Date]:[Test Finish Date]])+1,1))*
ROW(partsTbl)-ROW(partsTbl[#Headers])),
1),
"")
$A3=partsTbl returns a 2D array like {FALSE,FALSE,TRUE,FALSE;FALSE,FALSE, …} to find the part number in the table
Since your start/finish dates in the partsTbl are not always at the beginning/end of the month, we need to convert them to such before we compare the dates in B2:F2
(B$2>DATE(YEAR(partsTbl[[Test Start Date]:[Test Start Date]]),MONTH(partsTbl[[Test Start Date]:[Test Start Date]]),0))
And similar for the end of the month.
We now have a 2D-array of {FALSE,FALSE,TRUE,FALSE...} where the TRUE matches the part number as filtered by the dates.
ROW(partsTbl) returns a matching array of the row numbers in the table (and we subtract the row number of the Header row to determine the row within the data).
When we do our multiplication, we then get an array where the largest value will be the desired row
INDEX, referencing column 1, will then return the appropriate Plant #

How to report cell value to another cell on excel

I'm entering datas in A column of a table. According to the datas, I making sums from the yellow cell (actually this yellow cell is the high value of the A column). So all 10 cells, there is a sum until the end of datas.
I'm looking for automatically report the seven first grey cells (the sums)to another table. The problem is, according to the datas, high value is not at the same place so the sums are not to the same place too.
How can I do ?
Thank you for your help
MY ERROR :
And the message when I press ctrl maj enter in same time :
You might use this array formula in your report.
=INDEX($F:$F,SMALL(ROW($F$4:$F$117)+(100*(F$4:$F$117="")), ROW(F1)))&""
Bear in mind that, as an array formula, it must be confirmed with Control+Shift+Enter. Enter the formula in the row where you have Somme = 1, then copy down to 6. Note that Row(F1) is a counter. You have a similar counter (1 to 6) in F124:F130. Therefore you can replace ROW(F1) with $F124 (if that is where the "1" is) to make it easier to understand, perhaps.
The formula retrieves the value of the 1st, 2nd, 3rd etc non-blank cell in the range F4:F117. If those cells contain a formula they will be considered "blank" if their result equals "".
BTW, if you don't always have 113 results to evaluate you might consider giving a name to the range E4:E117. For example, if you name that range as "Results" then =SUM(Results) would be the same as =SUM($E$4:$E$117), but as you insert or delete rows within the named range the formula doesn't need to be amended. Use of a named range would simplify understanding your existing formula. You could do the same with column F.
Finally I find a solution to report the values from F to another table. As values positions are dependant of the MAX raw in E (every 10 cells) I make this formula :
For the first : INDEX(E4:F117;EQUIV(GRANDE.VALEUR($E$4:$E$117;1);$E$4:$E$117;0)+10;2)
For the second :
INDEX(E4:F117;EQUIV(GRANDE.VALEUR($E$4:$E$117;1);$E$4:$E$117;0)+20;2)
Etc...

Changing countif range automatically

I'm using this formula to count the word red in the last 30 days but the range is not changing when a new row is added at the bottom.
How can I change the formula so when a new row is added at the bottom the range is adjusted automatically? The quantity of rows to check is always 30.
=COUNTIF(D2433:D2463, "Red")
Another technique is using a dynamic named range:
Formula > Name Manager > New: Give a Name first and then insert the following formula into Referes to field. Also see the picture.
=INDEX(Sheet1!A:A,1):INDEX(Sheet1!A:A,INDEX(MAX((Sheet1!$A:$A<>"")*(ROW(Sheet1!A:A))),0))
This should give you a range like $A$1:$A$300 depends where the last non-empty cell is.
Now in the cell that you want to evaluate, add this formula:
=COUNTIF(rng,"red")
Please note rng is the named range that you should change to the name you want to use.
This will find the last cell and even work for blank cells. Try and let me know if you have any question.
Use the following:
=COUNTIF(OFFSET($D$2433,0,0,30,1),"Red")
The references you are using $D$2433 till $D$2463 count 31 if you need 31 change in the above formula 30 to 31
Offset will start in $D$2433 and count the rows down in the same column
Countif will count if Red
Update
If in column D you insert only Data to be counted, you can use :
=COUNTIF(OFFSET(INDIRECT("$D$"&MAX(IF($D:$D<>"",ROW($D:$D),0))),0,0,-30,1),"Red")
This is an array formula press Ctrl+Shift+Enter instead of just Enter
The new formula will find the last non empty row in column D and Indirect will correct the formula automatically
You need a relative cell reference. You can do this with the
=OFFSET()
function.
=COUNTIF(INDEX(D:D,AGGREGATE(14,6,ROW(D:D)/--((D:D)<>""),1)-30):INDEX(D:D,AGGREGATE(14,6,ROW(D:D)/--((D:D)<>""),1)),"Red")
Conditions:
There all rows beneath the last row must be blank
There cannot be any blank row within the last 30 row or your count may be off.
This is an array like function. If you use full range references it checks 1048576 cells each time the aggregate function references the full column range. As such if you use the formula a lot you can bog down your computer, if you are only using it a couple of time you will probably be ok.

Dynamic reference to the above cell

In my Excel worksheet, every 25 rows or so (this number is subject to change), a cell in column C contains a progressive number, identifying a set. Right now, there is a simple formula, e.g. in Cell 34:
= C9 + 1
When The number of rows above C34 changes, the formula updates automatically. No issue with that.
I am now experimenting with a macro that inserts a set in between two existing sets; therefore another number that should fit in the progression, and the following numbers should adapt.
I thought that formulas should change, to find the first number above the current cell and add +1.
Trying a solution from this link, I came up with the following formula:
=LOOKUP("z";$C$9:OFFSET(INDIRECT(ADDRESS(ROW();COLUMN()));-1;0))+1
It seems however that it only searches for text, giving a #N/Awhen there is no text and a #VALUE! when there is text; if I do not add the +1, it works fine.
I also tried
=LOOKUP(2;1/(C$9:C9<>"");C:C)
As explained in the link but all I get is 0
How do I modify these formulas to give me the expected result?
Assuming than the number of the first set is in A1,
enter this formula
=INDEX(A:A,MATCH(1E+100,OFFSET(A$1,,,ROW()-1)))+1
in the counting cells (A5,A10, A16 in the example):
Then you can insert rows for a new inserted set, for example:
When ypu copy the same formula into C10,
the set numbers update accordingly:
And you can fill the text elements of the set:

Resources