finding next empty row - excel

This might be easy for many but I need to solve an issue which is following;
I have the following formula which finds the empty row after D4.
=MATCH(TRUE;D4:D1048576="";0)+3
After this I want to be able to find the empty row from another defined cell, say D10.
How can I do this?

Try this as an array formula - Ctrl+Shift+Enter:
=MIN(IF(D4:D100="",ROW(D4:D100)))
It works from D4 to D100, providing the first empty value.

If you're looking to use same formula to match next cell then use
For blanks after D4
=MATCH(TRUE,INDEX(ISBLANK(D4:D1048576),0),0)
For blanks after D10
=MATCH(TRUE,INDEX(ISBLANK(D10:D1048576),0),0)

To find the A1th blank cell, you can use the following formula:
=AGGREGATE(15,6,ROW(D:D)/--ISBLANK(D:D),A1)
How it works
AGGREGATE(15,6,..) is like SMALL(..), but skips any error values.
ROW(..) provides the row number of the cell provided
ISBLANK(..) is TRUE for blank cells or FALSE for non-blank cells
-- converts TRUE to 1 and FALSE to 0. This means that ROW(D:D)/--ISBLANK(D:D) will be either the Row Number (for blank cells) or a #Div0! error (which AGGREGATE will skip)
This produces a list of row numbers for all the blank cells, and you then use the AGGREGATE function to get the kth item in that list.
Taking it a step further
So, you want the 1st item larger than a specific row. We change the last argument in AGGREGATE to 1, and swap change our "Error out" code from ISBLANK(D:D) to AND(ISBLANK(D:D), ROW(D:D)>A1), to get the first blank row after the row number stored in A1:
=AGGREGATE(15, 6, ROW(D:D)/--AND(ISBLANK(D:D), ROW(D:D)>A1), 1)

Related

Find the location of the first blank cell in a column with header rows

I am trying to find the location (row number) of the first blank cell in a column of data. Previous questions (such as this one) have helped, but by data contains header rows (7 in this case), which may be blank. Therefore, I am only interested in blank cells from row 8.
My attempts so far have tried the formula below, but thought it seems to create the lookup_array I want, it doesn't work with match_type set to -1. Don't understand why.
=MATCH(8, IF(ISBLANK(A:A), ROW(A:A), 0),-1)
This just gives #N/A for some reason. The IF statement appears to return the correct data, e.g. {0,0,3,0,5,0,0,0,9,0,0,0,13,0,...} for blanks in rows 3, 5, 9 & 13, but expect the MATCH to return 9, as the smallest match greater than 8.
PS - It's important that only the row is referenced, as I don't know how long the data block will be and the formula should work with any length data.
As pnuts commented in the answer you linked, you can use the following formula:
=MATCH(TRUE,INDEX(ISBLANK(A2:A1048576),0,0),0)
in your case just change the 2 to the first row you want to count from:
=MATCH(TRUE,INDEX(ISBLANK(A8:A1048576),0,0),0)
This will give you the first position of the empty blank, starting from the 8th Row. If it is in A9, this will return "2".
The alternative you had in your comment:
=MATCH(TRUE,IF(ISBLANK(A:A), ROW(A:A), 0)>7,0)
also works but MUST be entered as an array formula by pressing the combination ctrl + shift + enter when entering the formula:
{=MATCH(TRUE,IF(ISBLANK(A:A), ROW(A:A), 0)>7,0)}
If the cells are populated by a formula use
=MATCH(TRUE,INDEX(*"RANGE"*=""),0)

Vlookup with wildcard not working (partial string match) on long values

I understand the basic use of the vlookup with wildcard but I'm running into a problem lately.
I need to lookup a value that contained in a cell as a part of string. In the below Sample I look up colA in the colC, with should be found, then return the values in col D into col B.
I use =VLOOKUP("*"&A1&"*",C$1:D$2,2,0), and it only works for B1.
Why do B2 & B3 don't work out the same way? Any solution?
Sample:
As per your investigation and comment by Axel, VLOOKUP doesn't work with values over 255 characters in length. A workaround is use an array formula with the SEARCH function which handles much longer values. Double click into cell B1 and paste this formula, then save it by pressing CTRL + SHIFT + ENTER instead of just pressing Enter by itself:
=INDEX($D$1:$D$2,MATCH(TRUE,ISNUMBER(SEARCH(A1&",",$C$1:$C$2&",")),0))
If you enter it correctly, selecting the cell will show {curly braces} around the formula and it should evaluate to your desired result.
This formula first creates an array searching for the position of A1 in every cell in C1:C2. The array will consist of numbers (when A1 is found) and errors (when A1 is not found).
ISNUMBER then creates an array of TRUE (when A1 is found) and FALSE (when A1 is not found)
MATCH then finds the first TRUE value in the array.
INDEX then returns the corresponding value from the D1:D2.
Edit: The formula now searched for the value in A1 followed by a comma. This ensures that an exact match is made. To also ensure that the formula can match against the last value in any cell in column C, a comma is also added to the end of the values in column C.

Finding value that does not match while using SumProduct formula

In the following formula I sum up values in a column, I like to expand this so that it discounts values, if a value in another column ends with a "*D".
So far I have got it so that it sum only those that end in a "*D".
=SUMPRODUCT(SUBTOTAL(9,OFFSET($DY$16,ROW($DY$16:$DY$273)-ROW($DY$16),,1)),--ISNUMBER(SEARCH("*D",$EB$16:$EB$273)))
Question 1: How to reverse the formula to exclude value "*D"?
The --ISNUMBER part of your formula evaluates TRUE whenever the "D" is located
Changing this part to -ISERROR will evaluate TRUE whenever the "D" is not located
=SUMPRODUCT((IFERROR(SEARCH("D",CategoryRange),"-")<>LEN(CategoryRange))*SumRange)
should work if there is only on D.
CategoryRange is the range of cells in Category code column and SumRange is the range of cells in column to be summed over
It works for me. IFERROR(SEARCH("D",CategoryRange),"-") finds the position of 'D' in the Categore Code column, if it is not equal to LEN(CategoryRange) then the 'D' is not at the end, which creates a boolean array that you want. Please check it stepwise with "Evaluate Formula" in excel.

Is there a 2 Value Look up function in MS Excel that can perform the following?

I am going crazy over this. It seems so simple yet I can't figure this out. I have two worksheets. First worksheet is my data. Second is like an answer key. Upon checking checking, A1:B1 in Sheet 1 is a match with the conditions in Row 52 in SHEET 2, therefore, the value in Column C is "MGC". What is the formula that will perform this function? It's really hard to explain without the data so I pasted a link of the sample spreadsheet. Thank you so much in advance.
sample spreadsheet here. https://docs.google.com/spreadsheets/d/1_AjuNfCdGfEM-XkqPa6W4hSIxQg4NM2Vg4c2C1pQ_vQ/edit?usp=sharing
screenshot here. (wont let me post i have no reputation)
In Sheet2, insert a column in front of Column A and put the formula in A2 =C2&D2.
Then in Sheet1, Cell C2 the formula =vlookup(A2&B2,Sheet2!A:B,2,0).
the first make a concatenated key to lookup, then the second looks up that key.
How about a index(match())? If I've understood correctly you need to match across both the A and B column in sheet one, checking for the relevant values in B and C on sheet 2 to retrun worksheet 2 column a to worksheet 1 column c.
third version try:
=INDEX(Sheet2!$C$1:$C$360,MATCH(Sheet1!A1&Sheet1!B1,Sheet2!$B$1:$B$360&Sheet2!$C$1:$C$360,0))
Basically what this does is use concatenation, the & operator, to specify you are looking for "Criteria A" & "Criteria B" in sheet 1, which makes the string "Criteria A Criteria B", which is supplied in the first part of the match function.
In the second it then says match this against all of my variables in sheet 2 in the same way with concantenation.
The final part of match function (0) specifies you want an 'exact' match
It then supplied this as a reference to the index function, which then finds the row intersecting with the value you want, and returns that.
As noted here https://support.microsoft.com/en-us/kb/59482 this is an array formula, so it behaves differently, and must be input differently. https://support.office.com/en-za/article/Guidelines-and-examples-of-array-formulas-7d94a64e-3ff3-4686-9372-ecfd5caa57c7
There are (at least) 2 ways you could do this without VBA.
USING A SORTED LIST
The first relies on the assumption that your data can be re-sorted, so that everything "Unreported" is in the top, and everything "reported" is together below that (or vice versa). Assuming that this is the case (and it appears to already be sorted like this),we will use the function OFFSET to create a new range which shows only the values that align with either being "Unreported" or "Reported".
Offset takes a given reference to a point on a sheet, and then moves down/up & left/right to see what reference you want to return. Then, it returns a range of cells of a given height, and a given width. Here, we will want to start on Sheet2 at the top left, moving down until we find the term "Unreported" or "Reported". Once that term is found, we will want to move one column to the right (to pull column B from sheet 2), and then have a 'height' of as many rows as there are "unreported" or "reported" cells. This will look as follows in A1 on sheet 1, copied down:
=OFFSET(Sheet2!$A$1,MATCH(A1,Sheet2!A:A,0)-1,1,COUNTIF(Sheet2!A:A,A1),1)
This says: First, start at cell A1 on sheet2. Then find the term in A1 (either "unreported" or "reported", on sheet2!A:A (we subtract 1 because OFFSET starts at A1 - so if your data starts at A1 we need to actually stay at "0". If you have headers on sheet2, you will not need this -1). Then, move 1 column to the right. Go down the rows for as many times as Sheet2 column A has the term found in Sheet1 A1. Stay 1 column wide. Together, this will leave you with a single range on sheet2, showing column B for the entire length that column A matches your term in sheet1 A1.
Now we need to take that OFFSET, and use it to find out when the term in Sheet1 B1 is matched in Sheet2 column B. This will work as follows:
=MATCH(B1,[FORMULA ABOVE],0)
This shows the number of rows down, starting at the special OFFSET array created above, that the term from B1 is matched in column B from sheet2. To use this information to pull the result from column C on sheet 2, we can use the INDEX function, like so:
=INDEX([FORMULA ABOVE],MATCH(B1,[FORMULA ABOVE],0))
Because this would be fairly convoluted to have in a single cell, we can simplify this by using VLOOKUP, which will only require the OFFSET function to be entered a single time. This will work as follows:
=VLOOKUP(B1,[FORMULA ABOVE],2,0)
This takes the OFFSET formula above, finds the matching term in B1, and moves to the 2nd column to get the value from column C in sheet2. Because we are going to use VLOOKUP, the offset formula above will need to be adjusted to provide 2 columns of data instead of 1. Together, this will look as follows:
FINAL FORMULA FOR SHEET1, C1 & COPIED DOWN
=VLOOKUP(B1,OFFSET(Sheet2!$A$1,MATCH(A1,Sheet2!A:A,0)-1,1,COUNTIF(Sheet2!A:A,A1),2),2,0)
OPTION USING ARRAY FORMULAS
The above method will only work if your data is sorted so that the REPORTED and UNREPORTED rows are grouped together. If they cannot be sorted, you can use an ARRAY FORMULA, which essentially takes a formula which would normal apply to a single cell, and runs it over an entire range of cells. It returns an array of results, which must be reduced down to a single value. A basic array formula looks like this [assume for this example that A1 = 1, A2 = 2...A5 = 5]:
=IF(A1:A5>3,A1:A5,"")
Confirm this (and all array functions) by pressing CTRL + SHIFT + ENTER, instead of just ENTER. This looks at each cell from A1:A5, and if the value is bigger than 3, it gives the number from that cell - otherwise, it returns "". In this case, the result would be the array {"";"";"";4;5}. To get the single total of 9, wrap that in a SUM function:
=SUM(IF(A1:A5>3,A1:A5,""))
In your case, we will want to use an array formula to see what row in Sheet2 matches A1 from Sheet1, and B1 from Sheet1. This will look like this:
=IF(Sheet2!$A$1:A$100=A1,IF(Sheet2!$B$1:$B$100,ROW($B$1:$B$100),""),"")
This checks which rows in column A from sheet 2 match A1. For those that do, it then checks which rows in column B from sheet 2 match B1. For those, it pulls the row number from that match. Everything else returns "". Assuming no duplicates, there should only 1 row number which gets returned. To pull that number from the array of results, wrap the whole thing in a MATCH function. Now that you have the row number, you can use an INDEX function to pull the result in Column C with that row, like this:
FINAL ARRAY FORMULA METHOD
=INDEX($C$1:$C$100,MAX(IF(Sheet2!$A$1:A$100=A1,IF(Sheet2!$B$1:$B$100,ROW(Sheet2!$B$1:$B$100),""),"")))
Remember to confirm with CTRL + SHIFT + ENTER instead of just ENTER, when you type this formula. Note that I didn't refer to all of Sheet2!A:A, because array formulas run very slowly over large ranges.
The following formula should work without making any changes to the datasheets.
=INDEX(Sheet2!$A$1:$A$360,MATCH(Sheet1!A1,IF(Sheet2!$C$1:$C$360=Sheet1!B1,Sheet2!$B$1:$B$360),0))
Remember to save this formula as an array with CTRL+SHIFT+ENTER
Documentation on how to use INDEX and MATCH against multiple criteria can be found on Microsoft Support.
It's not clear what you want to do with the multiples that do not have corresponding matches. txed is listed as Unreported twice in Sheet1; kntyctap is listed as Unreported three times. There are only one corresponding match on Sheet2 for each of these.
Non-array Standard Formulas for multiple criteria matches
For Excel 2010 and above use this standard formula in Sheet1!C1:
=IFERROR(INDEX(Sheet2!$A$1:$A$999,AGGREGATE(15,6,ROW(1:999)/((Sheet2!$B$1:$B$999=A2)*(Sheet2!$C$1:$C$999=B1)), COUNTIFS(A$1:A1, A1, B$1:B1, B1))), "")
For version of Excel prior to 2010 use this standard formula in Sheet1!C1:
=IFERROR(INDEX(Sheet2!$A$1:$A$999, SMALL(INDEX(ROW($1:$999)+((Sheet2!$B$1:$B$999<>A1)+(Sheet2!$C$1:$C$999<>B1))*1E+99, , ), COUNTIFS(A$1:A1, A1, B$1:B1, B1))), "")
I've handled error with the IFERROR function in that latter formula. Excel 2003 and previous may have to use an IF(ISERROR(..., ...)) combination.

Cell Referencing Formula

Was using this formula SheetName!CellAddress
I need to import Data that is available on other 2 sheets namely (sheet2 and sheet3) into sheet 1 in a way such that
the row values will be alternate i.e one value from sheet 2 and other value from sheet 3 respectively
Have tried like this
=Sheet2!C2
=Sheet3!D2
when i dragged for other values i was get only values in the even cell like(c4,d4,c6,d6)
If i change the for formula to
=Sheet2!C1
=Sheet3!D1
i was get only values in the even cell like(c3,d3,c5,d5)
But what i need is continous cells in row( c1,d1,c2,d2,c3,d3...)
So what formula i need to use for getting this result
I am still not 100% clear on what the question is asking, so let me know if the below answer doesn't work for you.
It sounds like what you're looking for can be accomplished with OFFSET and clever use of IF statement.
Suppose your formulas will be in column A, starting in A2. Then enter the following formula into A2 (line split added for readability; remove it):
= IF(MOD(COUNTA(A$1:A1),2)=0, OFFSET(Sheet2!$C$1, COUNTA(A$1:A1) / 2, 0),
OFFSET(Sheet3!$D$1, COUNTA(A$1:A1) / 2, 0))
Then drag the formula down.
What it does:
MOD(COUNTA(A$1:A1),2)=0 - checks whether we're in odd row or even row.
COUNTA(A$1:A1)/ 2 - takes half of the number of non-empty cells immediately above the current cell.
OFFSET(Sheet2!$C$1, COUNTA(A$1:A1) / 2, 0) - takes the cell which is COUNTA(A$1:A1)/ 2 cells below Sheet2!$C$1.
Here's a fairly basic method:
Enter the first two formulas as Text - you can either do this by formatting the cell number as text or preceding the formula by an apostrophe.
Select cells and fill down to get:
=Sheet2!C2
=Sheet3!D2
=Sheet2!C3
=Sheet3!D3
=Sheet2!C4
=Sheet3!D4
...
Select the column and choose Data|Text to Columns|Finish to change text to values.

Resources