Nested If statement Excel - checking if value exists - excel

I have a spreadsheet with multiple row with varying data in the collumns eg:
Student NO Book1 Book 2 Book 3 Book 4 Book 5
X 12
Y 13 12 23 23 32
What I want to do is a Lookup of that mark in another table to see if the book exists, and to come back with NA if the mark isn't in the other spreadsheet.
I have the following code, although if the book isn't in the bounds then it comes back as blank. :'( is there a way to make it N/A.
=IF(ISNA(VLOOKUP(Q3,'Libary Books 21-06-13'!$A:$B,2,FALSE)),"",VLOOKUP(Q3,'Libary Books 21-06-13'!$A:$B,2,FALSE))
Many thanks

Just replace "" in the Value_if_true part of your formula with "NA".
=IF(ISNA(VLOOKUP(Q3,'Libary Books 21-06-13'!$A:$B,2,FALSE)),"NA",VLOOKUP(Q3,'Libary Books 21-06-13'!$A:$B,2,FALSE))
EDIT BASED ON COMMENT:
The best way to understand these kinds of nested formulas is to make them as simple as possible so that you can make sure what is happening.
I set up two columns, Book Name in column A and Nested If in column B on a single sheet.
The formula in column B is
=IF(ISNA(A2), "", IF(A2="", "Doesn't Exist", A2))
I copied and pasted that formula to all rows. Here are the results:
Book Name Nested If
The Sun Also Rises The Sun Also Rises
Doesn't Exist
#N/A
You can use the formula above as your template.

Related

vlookup values from other sheets disappear when file closed

I've got a group of registers that I created for our volunteers and youth club members. Each register spreadsheet is from Sept to July. More and more volunteers and young people are staying with us for longer so I have been trying to create a vlookup that takes the total hours they volunteered from the previous years and add it to the current year total. This chains about 3-4 previous years of registers together. ie, 2014-15 adds to 2015-16 total, 2015-16 adds to 2016-17 total, 2016-17 adds to 2017-18 total, etc. The vlookup works great when all the previous years registers are open, but once I close one I get a #n/a error. How can I prevent the error msg and keep my formula working without opening all the documents?
Have you tried to specify the complete workbook path in your vlookup formula?
I.e. something like this:
=VLOOKUP(B1,'C:\School Projects\University\[Assignment.xlsx]DataYear'!$A3:$D10,3,FALSE)
Where:
Assignment.xlsx - is the name of workbook
DataYear - is the name of the worksheet
EDIT:
Since you mention you have tables when you are using your VLOOKUP you should use the Index + Match, is way more flexible. [#Data] won't work and VLOOKUP works best only if the return column is next to the search column, i.e. Column 1 is search and Column 2 is return values.
Example of applying INDEX + MATCH in table:
If I have an table in Book2.xlsx
And my table is named table 15:
Let's assume I have another woorkbook (Book1.xlsx). I want to check how many Quantity the person Sally sold. (My formula should return: 2, Cell C3).
Then my formula should be in the other excel book (Book1.xlsx):
=INDEX('G:\Folder Stuff\Book2.xlsx'!Table15[Qty],MATCH(B2,'G:\Folder Stuff\Book2.xlsx'!Table15[People],0))
So to apply for tables you should use:
Table15[Qty] - Return quantity, which refer to my column Qty in my example
Table15[People] - column to lookup my search value (sally), which refer to my column People in my example
Logic of INDEX + MATCH:
=INDEX(Column where result should be return,MATCH(lookup_value, Column where lookup value exist, Exact or Approximate Match)
So your formula should be something like this:
=INDEX('C:\Users\COG Youth Services\Dropbox...\Registers\Volunteers attendance record 2017-18.xlsx'!Table14[Name of the table column in Column 37],MATCH(StudentLookup,'C:\Users\COG Youth Services\Dropbox...\Registers\Volunteers attendance record 2017-18.xlsx'!Table14[Name of the table Column where StudentLookup exist],0))

Mode Text 2nd most common text value

IFERROR(INDEX($I$7:$I,MODE(IF($I$7:$I<>"",MATCH($I$7:$I,$I$7:$I,0)))),"No data")
With this formula, which calculates the most common text value, I need to have the 2nd most common.
Column I content:
Apple
Orange
Apple
Apple
Orange
In this example, I need to get Orange. How is that possible? I can't figure how.
A PivotTable might suit:
and copes with ties for rank.
You can extract the most frequent item in the list with an array formula.
=INDEX(MyList,MATCH(MAX(COUNTIF(MyList,MyList)),COUNTIF(MyList,MyList),0))
Note that an array formula must be confirmed with Shift+Ctl+Enter instead of the customary singular Enter required for normal formulas. When entered wrongly it will display a #NUM! error.
For simplicity's sake I have used a named range MyList in the formula. However, if you prefer, you can replace the name with something like $I$7:$I$1000.
To extract the second-most frequent expression in the list you could use a formula constructed analogue to the above.
=INDEX(MyList,MATCH(LARGE(COUNTIF(MyList,MyList),MAX(COUNTIF(MyList,MyList))+1),COUNTIF(MyList,MyList),0))
This formula is built on the logic that n equals the highest number of occurrences. Therefore the second highest must rank as n + 1, being MAX(COUNTIF(MyList,MyList))+1) in the above formula. By the same method the third ranked could be extracted.
You can embed these formulas in an IFERROR() function.
I found this on Mr Excel
Return most common, 2nd most common, 3rd most common, etc. text string in an array
Spreadsheet Formulas
Cell ___ Formula 'Notice that the cells are B2, D2, E2. Column C is blank
B2 =IF(A2="","",IF(COUNTIF(A$2:A2,A2)=COUNTIF($A$2:$A$100,A2),COUNTIF($A$2:$A$100,A2)+(ROW()/1000),""))
D2 =IF(ROWS($1:1)>COUNT(B:B),"",INDEX(A:A,MATCH(LARGE(B:B,ROWS($1:1)),B:B,0)))
E2 =IF(D2="","",COUNTIF($A$2:$A$100,D2))<br><br>
Results
___ A ________ B ___C ___D _________E
1 Data Set:___Helper ____ Name ____ Occurrences
2 Harmon _____________ Williams ______4
3 Smith _______________ Smith ________3
4 Smith _______________ Harmon ______2
5 Harmon_____ 2.005
6 Williams
7 Williams
8 Smith _______3.008
9 Williams
10 Williams ____4.010
you can try to tie this all together in a single formula but it's simpler and more agile in a spreadsheet environment to just break out the problem in a few separate steps.
take a given column of values you're wanting to count/rank - i'll call it RankList in examples below.
if you're not setting named ranges (do yourself a favor and use named ranges) you'll want this to be your column range - i.e. A:A
now in another column use
=unique(RankList)
there's your list of unique values, now we just need to count the instances of each unique value in the original RankList - this is simple - in the next column over simply use
=countif(RankList,B1)
B1 above represents the cell adjacent to the formula, wherever that might be on your sheet. now autofill the formula in with the relative cell value for each item. now all of your items are counted by instance.
now we want to sort them by value, highest to lowest. create another named range, selecting the two columns containing the =unique(RankList) and =countif(RankList,B1) formulas that were just created, i'll refer to it as UniqueCount
use the following
=sort(UniqueCount, 2, false)
that's it. again you can accomplish this by stacking formulas like in the above examples, but in practice i've found that you won't know what you'll want to do additionally with your data/sheet later on. keeping it broken up in discrete steps like this makes it much easier to make adjustments.

If/And statements and lookup in Excel

My question is about VBA excel code.
I want to maybe write a macro but i'm not very familiar with coding so I was looking for some guidance.
Basically I have an excel spreadsheet with a table with some fields but no values filled in and then I have a seperate spreadhsheet with a table of values that I'd like to get into the first spreadsheet
For Example this would be a brief breakdown of what I have:
Height: *blank cell to be populated*
length: *blank cell to be populated*
Width: *blank cell to be populated*
I want to set up a macro so that when I type 10 into the first row (note that there are two columns, one for the noun e.g "Height" and one for the actual value.), that it will look up my second worksheet with the table of values and automatically populate the field for the length and the width based on the adjacent values in the calculations table.
I hope this is making sense!
I've tried creating a new macro and writing a basic if/and function but the macro won't run. I've enable macro's but it's telling me that my code has no defined object. Because I couldn't get that running, I didn't look to much into incorporating the lookup command.
I've done some research online into basic if/and statements and they don't seem that difficult, however my table of values has 126 different rows, each one with a height. lenght and width value, so it would be 3 horizontal columns by 126 vertical rows. It seems excessive to me to have to do that many if/and statements.
I'm also finding it difficult to do a lookup of a different worksheet. This table is very big and i'd rather have it on a seperate sheet rather than put it to the far side of the first sheet and run the lookup there (it seems to messy to me)
Sorry If I haven't explained this very well. Any help is greatly appreciated!
I suggest that you do not use VBA. You can achieve this with the VLOOKUP function.
Here are some examples that I have in Sheet2.
H L W
1 2 3
5 10 12
10 11 12
15 15 15
For convenience, I define a name, myHLW, which is defined as sheet2!$a$1 to sheet2!$c$5.
In Sheet1, I type Height Width Length in a1, b1, and c1.
I type 10 in a2. I then entered this formula in b2: =VLOOKUP($A2,myHLW,2). This tells Excel to (a) look up the value in a2 (currently 10). (b) Look in the named region, myHLW. (c) Put whatever is in column 2 in the found row. Excel fills in 11 for me.
I then entered this formula in c2: =VLOOKUP($A2,myHLW,3). This tells Excel to look up the value in a2 (currently 10), using the named region, myHLW, and place whatever is in column 3 in the found row. Excel fills in 12 for me.
I copied the formulas down, entering different heights. It looks like this:
Height Length Width
10 11 12
5 10 12
1 2 3
3.14159 2 3
Note that the heights in Sheet2 must be in ascending order. Note also that for a height that is not found (3.14159), it uses the height for 1 (the largest value that was not exceeded.)
You may also add a fourth argument, for example =VLOOKUP($A2,myHLW,3,FALSE). If the fourth argument is false, Excel will require an exact match. If you had pdone this for VLOOKUP, Excel would have placed #N/A if there were no match.

Find something in column A then show the value of B for that row in Excel 2010

Basically my problem is that I have a string in one cell in excel, I then need to see if that string exists in another row (not one cell but the whole row) and if so then print the contents of another cell in the same row but in another column.
I will give a basic example:
Title Answer
Police 15
Ambulance 20
Fire 89
Now I need to scan the title column for, say, "Police" and then populate the cell with the value under Answer (in this case 15).
I cant just say IF(A2="Police";B2;"" as I need the scan the whole of the Title column.
I have tried using IF(COUNTIF(A$2:A$100;"Police"); which scans the contents of A2 to A100 for the string Police, and know how to make it print a constant (just put something after the ;) but cant work out how to make that "constant" a variable that changes depending on the found row. So if the COUNTIF found Police in cell A44 then the answer to my formula would be B44, the same as if it found Police in A62 then my formula should show B62
I hope this makes sense and that someone can help me :)
Note that I am using excel 2010 and need a normal formula as I can not use scripting for this document.
EDIT:
Here is what I have so far, note that the spreadsheet I am using is far more complex than the "simple" example I have in the question...
=IF(ISNUMBER(FIND("RuhrP";F9));LOOKUP(A9;Ruhrpumpen!A$5:A$100;Ruhrpumpen!I$5:I$100);"")
This is showing "RuhrP" in every answer where "RuhrP" is found in F9 and not the answer I want which should be that found in RuhrPumpen!I$5:I$100 where the cell index is the same as that for the A coloum where A9 was found. Again, sorry for the complexity I cant think of any better way to word it.
I note you suggested this formula
=IF(ISNUMBER(FIND("RuhrP";F9));LOOKUP(A9;Ruhrpumpen!A$5:A$100;Ruhrpumpen!I$5:I$100);"")
.....but LOOKUP isn't appropriate here because I assume you want an exact match (LOOKUP won't guarantee that and also data in lookup range has to be sorted), so VLOOKUP or INDEX/MATCH would be better....and you can also use IFERROR to avoid the IF function, i.e
=IFERROR(VLOOKUP(A9;Ruhrpumpen!A$5:Z$100;9;0);"")
Note: VLOOKUP always looks up the lookup value (A9) in the first column of the "table array" and returns a value from the nth column of the "table array" where n is defined by col_index_num, in this case 9
INDEX/MATCH is sometimes more flexible because you can explicitly define the lookup column and the return column (and return column can be to the left of the lookup column which can't be the case in VLOOKUP), so that would look like this:
=IFERROR(INDEX(Ruhrpumpen!I$5:I$100;MATCH(A9;Ruhrpumpen!A$5:A$100;0));"")
INDEX/MATCH also allows you to more easily return multiple values from different columns, e.g. by using $ signs in front of A9 and the lookup range Ruhrpumpen!A$5:A$100, i.e.
=IFERROR(INDEX(Ruhrpumpen!I$5:I$100;MATCH($A9;Ruhrpumpen!$A$5:$A$100;0));"")
this version can be dragged across to get successive values from column I, column J, column K etc.....
Assuming
source data range is A1:B100.
query cell is D1 (here you will input Police or Fire).
result cell is E1
Formula in E1 = VLOOKUP(D1, A1:B100, 2, FALSE)
I figured out such data design:
Main sheet:
Column A: Pump codes (numbers)
Column B: formula showing a corresponding row in sheet 'Ruhrpumpen'
=ROW(Pump_codes)+MATCH(A2;Ruhrpumpen!$I$5:$I$100;0)
Formulae have ";" instead of ",", it should be also German notation. If not, pleace replace.
Column C: formula showing data in 'Ruhrpumpen' column A from a row found by formula in col B
=INDIRECT("Ruhrpumpen!A"&$B2)
Column D: formula showing data in 'Ruhrpumpen' column B from a row found by formula in col B:
=INDIRECT("Ruhrpumpen!B"&$B2)
Sheet 'Ruhrpumpen':
Column A: some data about a certain pump
Column B: some more data
Column I: pump codes. Beginning of the list includes defined name 'Pump_codes' used by the formula in column B of the main sheet.
Spreadsheet example: http://www.bumpclub.ee/~jyri_r/Excel/Data_from_other_sheet_by_code_row.xls
Guys Its very interesting to know that many of us face the problem of replication of lookup value while using the Vlookup/Index with Match or Hlookup.... If we have duplicate value in a cell we all know, Vlookup will pick up against the first item would be matching in loopkup array....So here is solution for you all...
e.g.
in Column A we have field called company....
Column A Column B Column C
Company_Name Value
Monster 25000
Naukri 30000
WNS 80000
American Express 40000
Bank of America 50000
Alcatel Lucent 35000
Google 75000
Microsoft 60000
Monster 35000
Bank of America 15000
Now if you lookup the above dataset, you would see the duplicity is in Company Name at Row No# 10 & 11. So if you put the vlookup, the data will be picking up which comes first..But if you use the below formula, you can make your lookup value Unique and can pick any data easily without having any dispute or facing any problem
Put the formula in C2.........A2&"_"&COUNTIF(A2:$A$2,A2)..........Result will be Monster_1 for first line item and for row no 10 & 11.....Monster_2, Bank of America_2 respectively....Here you go now you have the unique value so now you can pick any data easily now..
Cheers!!!
Anil Dhawan

Copy data between excel spreadsheets with a given value as a parameter

Say I have two spreadsheets.
One of the spreadsheets has a table like this:
**Sheet 1**
A B C D
1 Name Age Rank Number
2 George 22 Master 12
3 Paul 21 Acolyte 22
4 Jimmy 32 Horse 33
5 Agnor 12 Cheetah 90
The other spreadsheet looks like this:
**Sheet 2**
A B C D
1 Name Age Rank Number
2 George
3 Paul 21 22
4 Agnor
I want to copy Ages from sheet 1 to sheet 2. So I would copy George, Paul, and Agnor's age, and ignore Jimmy. Which function should I use to copy data based on an existing value?
Is there something like:
foreach VAL in Sheet1
if(Sheet1.Name.EqualsIgnoreCase(Sheet2.Name))
{
Sheet2.Age = Sheet1.Age;
}
I looked this up, and a lot of people are saying to use VLookup, but I can't figure out how that would apply.
EDIT
I found a similar resolved question (No idea HOW I missed it) here: Compare and copy data between worksheets
However, I'm still a little shaky on how to implement this (I'm using Excel 2007).
vlookup would be the easiest way to go.
I will use cell B2 in sheet2 as the reference to try to explain the function
=VLOOKUP(A2,Sheet1!$A$2:$D$5,2,FALSE)
The first parameter is the data you are using for a lookup - you may want to change that to $A2 if you copy the formula around the sheet
The second parameter is where the data is that excel needs to find the value you referenced in the first parameter - use dollar signs. The data doesn't tend to move
The third parameter tells excel what info to return - the 2 means give me the 2nd piece of data
The last parameter tells excel if it can use a close match (FALSE for an exact match)
Now to follow Excel and see what it returns.....
First, it looks for George in the data (it knows it has to be an exact match from the fourth parameter)
Next, it finds the row George -- 22 -- Master -- 12 and gives the function the second value (22 in this case)

Resources