Excel Formula not accepted but no reason for error - excel

I have a if formula with a number of criterias it has to match.
When I have shortened the formula down it works from beyond - IF(LEFT(A6,1)="2"
but there are no reasons it should error at this point? Any help?
=IF(LEFT(A6,2)="10","Area 1",IF(LEFT(A6,2)="12","Area 2",IF(LEFT(A6,2)="13","Area 3",IF(LEFT(A6,2)="14","Area 4",IF(LEFT(A6,2)="15","Area 5",IF(LEFT(A6,2)="16","Area 6",IF(LEFT(A6,2)="17","Area 7",IF(LEFT(A6,1)="2","Bulk",IF(LEFT(A6,1)="4","Intl",IF(LEFT(A6,2)="7","CGCC","Ad-Hoc"))))))))))

You can try combining IF and VLOOKUP.
=IF(LEFT(A6,1)="4","Intl",IF(ISNA(VLOOKUP(LEFT(A6,2),{"7","CGCC";"10","Area 1";"12","Area 2";"13","Area 3";"14","Area 4";"15","Area 5";"16","Area 6";"17","Area 7"},2,FALSE)),"Ad-Hoc",VLOOKUP(LEFT(A6,2),{"7","CGCC";"10","Area 1";"12","Area 2";"13","Area 3";"14","Area 4";"15","Area 5";"16","Area 6";"17","Area 7"},2,FALSE)))
I embedded the array in the formula but you can prepare a table (assume G1:H7) like this:
and then use the VLOOKUP with the reference:
=IF(LEFT(A6,1)="4","Intl",IF(ISNA(VLOOKUP(LEFT(A6,2),G1:H7,2,FALSE)),"Ad-Hoc",VLOOKUP(LEFT(A6,2),G1:H7,2,FALSE)))
IFNA or IFERROR could also be used but they are not available in Excel 2003.

Your entire formula could be shortened to 2 VLOOKUP functions, by putting your data into a table, with your ID column on, say, column A of sheet2, and your results column on column B of sheet2. This would look as follows:
=IFERROR(VLOOKUP(LEFT(A6,2),'Sheet2'!A:B,2,0),IFERROR(VLOOKUP(LEFT(A6),'Sheet2'!A:B,2,0),"Ad Hoc"))
What this does is: first try to match the left 2 characters in A6 to one of your ID's in column A in sheet2. If that creates an error, it tries to match the left 1 character in A6 to one of your ID's in column A of sheet2. Either way, it returns the matching value in column B of sheet2. If no match is found, it returns "Ad Hoc".

Related

I need to extract data from one column where condition matches from another column using index and match

In this sheet, I have a range in B1:C18, where I want to return column C values in G column where all values match with column B with the condition value in E1.
But I'm getting only top value from the Column C but not all (i.e., Sep 2 has two values 443 and 472) but it is returning only 443.
Could anyone look at the formula return in G1 as
={IF(ISERROR(INDEX($B$1:$C$18,SMALL(IF($B$1:$B$18=$E$1,ROW($B$1:$B$18)),ROW(1:1)),2)),"",
INDEX($B$1:$C$18,SMALL(IF($B$1:$B$18=$E$1,ROW($B$1:$B$18)),ROW(1:1)),2))}.
Get the Answers in a column
Ok, I checked and your formula and it is correct too. I have modified it to be an ArrayFormula in the Google Sheets. Just check.
Formula 1
=ArrayFormula(IF(ISERROR(INDEX($B$1:$C$18,SMALL(IF($B$1:$B$18=$E$1,ROW($B$1:$B$18)),ROW(1:1)),2)),"", INDEX($B$1:$C$18,SMALL(IF($B$1:$B$18=$E$1,ROW($B$1:$B$18)),ROW(1:1)),2)))
You can try this formula too -
Formula 2
=ArrayFormula(IFERROR(INDEX($C$1:$C$18, SMALL(IF(E$1=$B$1:$B$18, ROW($C$1:$C$18),""), ROW())),""))
Just copy the formula in the cells of the respective column and you are good to go.
Get the Answers in a single cell
Use this Array Formula for your Google Sheets -
=ArrayFormula(TEXTJOIN(", ",TRUE,IF(B1:B18 = E1,C1:C18,"")))
It will aggregate all the values in a single cell.
Maybe you can try
=iferror(split(textjoin(", ", 1, filter(C2:C, B2:B=E1)), ", ", 1))
and see if that works ?

Excel VBA/Formula to find a cell that includes search term?

I was not sure how to really create the question...
But the problem I am having is this: I have a list (in rows) that relate to a regulatory document, and after trying to create some sort of for loop or elaborate VLookUp/Index formula, I'm requesting help.
For example:
Now I want to use the rows to find the corresponding section in the document. I've already extracted and formatted the compliance document so it is in excel format.
So what I really need is this: a formula or VBA script that can
1. take the compliance number (for example 1A-1 which exist in Cell A3) and go find a cell (in single column D) that has JUST 1A-1, not 1A-1.1, not 1A-1.1.2, etc. and return it to the adjacent cell to 1A-1, for example.
Many thanks ahead of time... I am so lost!! :/
VLOOKUP vs INDEX/MATCH
You can do the 'lookup' two ways (that I'm aware of):
Using VLOOKUP:
The B3 cell contains your formula
=IF(ISERROR(VLOOKUP(A3,C:D,2,FALSE)),"",VLOOKUP(A3,C:D,2,FALSE))
where 'FALSE' is indicating there has to be an exact match and the data doesn't have to be sorted.
Using INDEX with MATCH:
The F3 cell contains the Index/Match formula
=IF(ISERROR(MATCH(A3,C:C,0)),"",INDEX(D:D,MATCH(A3,C:C,0)))
where '0' is indicating there has to be an exact match and the data doesn't have to be sorted.
INDEX/MATCH preferable!?
The MATCH function finds the position (row number if whole column is used) of the found match. This way (there's another) of using the INDEX function uses exactly this found match to return a cell's value in that position (row) in ANY specified column range (column). So they are the ideal combination.
With the VLOOKUP function you have to additionally specify the column index (range_lookup) of a range which could get complicated when the columns aren't adjacent as in this case. Most importantly, the function doesn't work if the lookup data is to the right of the match data.
VLOOKUP NOT WORKING! INDEX/MATCH STILL WORKING!
try this formula
The formula in cells
B2: =INDEX(E:E,MATCH(A2,F:F,0))
C2: =INDEX(G:G,MATCH(A2,F:F,0))
MATCH(A2,F:F,0) is finding Cell A2 in column F (0 means it will find
exact match) and will return the first row number when it would find that
INDEX(E:E,MATCH(A2,F:F,0)) will return contents of column E where row number is returned by the Match formula

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.

Matching two columns in one sheet to two columns in another

I need to assign a status to a row based on a VLOOKUP query between two worksheets. The problem is that the identifier is not always unique. However, the identifier + a date value should be unique. I wanted to use:
=VLOOKUP(A3&H3,'OtherSheet'!D:E,1,FALSE)
with A3 being the identifier and H3 being the corresponding date. D in the other sheet is the identifier and E is the date column. However, I keep getting #N/A.
Does this mean that there are no matches with the "identifier+date" or is Excel looking for "identifier+date" in either column D or E? If the latter is true, how can I let Excel concatenate D and E when matching to the search pattern?
There's work around without using CTRL+Shift+Enter.
Use this formula that will match A3 in D column of othersheet and H3 with the date in column E of the othersheet.
=INDEX(OtherSheet!F:F,MATCH(1,INDEX((OtherSheet!D:D=A3)*(OtherSheet!E:E=H3),),0))
The formula will return data from F column of OtherSheet.
You can modify the range OtherSheet!F:F as appropriate.
That formula is looking to find A3 concatenated with H3 (identifier&date) in OtherSheet ColumnD that contains only identifiers, so will inevitably fail. Yes, Excel is looking for “identifier+date” in column D.
Excel will happily concatenate A3 with H3 ‘on the fly’ (within a formula) but will not so happily concatenate OtherSheet ColumnD and ColumnE values in the same way. The conventional solution, because usually simplest in a case like this, is to prepare for the VLOOKUP by adding a helper column that concatenates the D and E values while preserving these in the same row as the value sought.
Because VLOOKUP will only look to the right this is usually a column that is added to the left of the value being searched for, so say either in C or by insertion of a column immediately to the right of C. However, since you are only checking a single column the location is not critical. You might add this (in OtherSheet) as ColumnZ, with a formula such as:
=D2&E2
copied down to suit*. Again because you are only checking a single column it does not matter which row such a formula is placed in.
However, because only checking whether A3&H3 exists in OtherSheet a simple alternative may be to apply COUNTIFS:
=COUNTIFS(OtherSheet!D:D,A3,OtherSheet!E:E,H3)
Any result other than 0 from this should indicate that the combination being tested for exists in OtherSheet – without need for a helper column.
* Depending on the format of your identifiers it is possible that concatenation may introduce ambiguity. For example ID90 concatenated with 11/1/15 may not be distinguishable from ID901 concatenated with 1/1/15, so it may be advisable if taking this approach to introduce a delimiter, in both the VLOOKUP formula (say A3&"|"&H3 rather than just A3&H3) and therefore also in the helper column, say =D2&"|"&E2.
You likely would want to use Index/Match instead. Vlookup is tricky when it comes to searches for multiple things. Here's the way you would use Index/Match:
Without knowing how your spreadsheet is set up, here's how you could do it:
If I understand correctly, you want to use A3 to find the match in OtherSheet!D, and H3's match in OtherSheet!E. Index match is perfect for this. Instead of vLookup, use
=Index(OtherSheet!D:D&","&Text(OtherSheet!E:E,"mm-dd-yyyy"),Match(A3&H3,OtherSheet!D&OtherSheet!E,0)), and enter with CTRL+SHIFT+ENTER.
What the Index() will return is the concatenated Identifier and Date, separated with a comma. If, though, you have a table like this:
That index/match formula will return "Batman". The index to return is the named range G2:G5. You're looking for a match on A1 (the Identifier) and B1 (the Date), then you're searching for (in the order you just put) the Identifier to be in the range E2:E5, and the Date to be in F2:F5. When there's a match for both, it returns the name in G2:G5.
Here's a link to a site on using Index/Match, and another and its advantages over vlookup.

VLookup with empty cells

Here are my 2 columns
A B
Spain [EMPTY]
France Euros
Spain Euros
In another cell, I would like to write a formula that would write the currency of each country. like if I have:
C1=Spain, C2=France,
I would want to have
D1=Euros, D2=Euros.
I tried it with VLOOKUP, but it gave me
C1=[Empty], C2=Euros
Thank you very much for your time
As others have commented, VLOOKUP will return the first match it finds, thats why you get [EMPTY] for Spain.
You can work around this by adding an intermediate column. Lets assume you insert a column B with formula =IF(C1="","",A1) and copy down for all used rows.
Column D is Spain, France etc
Column E is now =VLOOKUP(D1,B:C,2,0)
IF you can SORT your columns, sort by Column A then by B descending (Z-A) then use the vlookup you're trying to use. THis will put the country with a value 1st so V-Lookup will return a vale instead of empty. When empty is returned, its becuase EVERY single instance of that entry in column A has an empty value. However if the entry in A has Multiple values, it will pick the first from descending order.
So do you have situations in which a entry in column A has multiple values beyond 1 currency and a blank entry?
However this has a pitfall in that the Order now matters so if data is added to this spreadsheet a reorder must occur each time.
I'm more a VBA than formula guy but this (horrible!) array formula will return the first non blank match
in D1 put
=IF(MAX(IF(--(A$1:A$6=C1)*LEN(B$1:B$6)>0,ROW(A$1:A$6),0))>0,INDEX(B$1:B$6,MAX(IF(--(A$1:A$6=C1)*LEN(B$1:B$6)>0,ROW(A$1:A$6),0))),"no match")
and press Shift - Ctrl - Enter together
how it works
IF(--(A$1:A$6=C1)*LEN(B$1:B$6)>0,ROW(A$1:A$6),0)) checks that A1 matches each of A1 to A6, and correspondingly whether B1 to B6 is non-empty.
If both these conditions are TRUE then the row number of these matches is placed in an array, if FALSE the formula returns zero. so the first array id {0,0,3,0,0,0}
If the MAX of this array is not zero then the formula returns this cell position from the B column using INDEX in INDEX(B$1:B$6,MAX(IF(--(A$1:A$6=C1)*LEN(B$1:B$6)>0,ROW(A$1:A$6),0)))
Else there is "no match"
I will shoot this to a formula genius called Barry Houdini to see how much he can shorten it
Enlarged sample (including a true blank result) below
I feel like a fraud here.....don't ask me any VBA questions!
I note that use of MAX actually means that your formula (and chris' amended version) actually gives the last non-blank match. You can also do that with a non-CSE LOOKUP formula, i.e.
=LOOKUP(2,1/(B$2:B$6<>"")/(A$2:A$6=C1),B$2:B$6)
which will return #N/A if there's no match
for the text "no match" instead then, assuming formula returns text values you can use 2003 compatible
=LOOKUP("zzz",IF({1,0},"No match",LOOKUP(2,1/(B$2:B$6<>"")/(A$2:A$6=C1),B$2:B$6)))
For first non-blank match you can use INDEX/MATCH in a similar way, i.e.
=INDEX(B$2:B$6,MATCH(1,(B$2:B$6<>"")*(A$2:A$6=C1),0))
confirmed with CTRL+SHIFT+ENTER

Resources