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)
Related
I have two workbooks that I need to pull data from workbook1, to workbook2. The identifier to achieve such is empID Now for eachempID I need to show what location(s) they worked. So sample data looks like this
Workbook1
empID.....Name....Address...City...State....Zip
1
2
3
4
5
Workbook2
empID.......locationworked
1 12
2 33
1 11
4 22
3 9
1 55
5 19
2 76
1 99
I have used this formula to return the data to a different cell for each empID
=IFERROR(INDEX($B$2:$B$8, SMALL(IF($A$11=$A$2:$A$8, ROW($A$2:$A$8)-ROW($A$2)+1), ROW(1:1))),"" )
But I want to create a Comma Separated list and put everything in one cell, like so
1 11,12,55,99
2 33,76
etc
Is there a way to modify the syntax so that a comma separated list is created like in my desired output?
In workbook 2, I added this formula to column C
=IFERROR(VLOOKUP(A1,A2:$C$50,3,0)&","&B1,B1).
This assumes that your data goes as far down as row 50. Replace $C$50 with whatever row is last in your spreadsheet.
If this is a variable list, use
=INDIRECT("A2:C"&MATCH(TRUE,D:D="",0),1)
in place of the
A2:$C$50
however don't forget to use Ctrl + Shift + Enter to set the formula to an array.
Next, copy this formula down all rows. The VLOOKUP will work up the sheet. Then you can reference this list from your report sheet (I believe in this case its Sheet 1) with a VLOOKUP. it will automatically pick the first instance of each employee ID which contains the csv list.
I'd like to point out that whilst bad_neighbor's solution is quite accurate and reusable for future data changes, it is often preferable to avoid lookups where possible, and to store calculated results as values, since these aren't perfectly efficient and tend to slow down the sheet something awful given a larger quantity of data, for example when filtering / unfiltering. It's worse in older versions.
So, if this list formatting were part of a manual operation, and assuming the requirement is for each list item to be in ascending order (per the question's output), I'd do the following instead:
If workbook2's order is important, add an index of the rows (D1 := 1; D2 := D1 + 1; paste values).
Sort workbook2 by [A ascending, B descending], including index if present.
Apply this formula to column C - a fillup version of the lookup.
C1 := IF(A1=A2,C2&", "&B1,B1)
Copy-paste special values column C.
Lookup from workbook1 + copy-paste special values.
Optionally sort back according to original index (D) in workbook2.
I need to compare my list of latitude/longitude (columns 4 and 5) with a database containing latitude/longitude data (columns 1 and 2) and its associated data (column 3). This associated data I need to ascribe to the relevant latitude and longitude in column 6. There are no duplicates in the database.
I have tried to use the index functionality etc but have had little luck.
DatabaseLat DatabaseLon Data Lat Lon CopiedData
31.2 -87.9 5 30.5 -87.1 3
31.9 -88.3 6 31.9 -88.4 10
31.9 -88.4 10 54 -87.1
31.1 -87.2 2 31.2 -87.9 5
30.5 -87.1 3
This was something close to what you were looking forward to, by just using formula than a macro/script.
Essentially done using a concatenate function and VLOOKUP.
Step 1. concatenate value from your database and add it under Col A.
Step 2. Use VLOOKUP as in the image and compare using the concatenated value.
=VLOOKUP(CONACTENATE(H2,I2), $A$2:$D$10,4, 0)
Note: the syntax is using LibreOffice the function name may slightly differ.
Most likely you will have to:
Write a VBA Excell macro script link
Make use of for each loop, to go through every cell of column 4 and compare it to the same row of column 1.
If they hold the same value you just check column 2 and 5 simply by adding 1 to the current column number, which will move you to the right. eg.
if cell E5 == A1 then [E +1 = F ] if cell F5 == B1, you have a match. So you can extract from C1 the Database number.
Or, take a look at this methods link
I can't help more, I don't work on windows sorry, and good luck.
I have data like this in an excel sheet:
1 2 3
4 5 6
What I am trying to do is come up with a formal that will give me the total of each row, something like this =A+B+C, so I can use this formula on each row...I have plenty of rows, The above is just and example, I have this =A1+B1+C1 is there away in excel to get A1 + B1 + C1 without the row number?
Please help, this would save me lots of time.
I have looked into =ROW to get the row number, can I use the sum function with the row function?
=SUM(A=ROW():B=ROW())
I found a solution to my problem:
=SUM(INDIRECT("A"&ROW()):INDIRECT("C"&ROW()))
This will work
=SUM(INDIRECT("A"&ROW()):INDIRECT("C"&ROW()))
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.
Good morning. I have been searching for some code either a formula or VBA to lookup values in a table. I have two tables that I am looking to migrate data from the old with the new. Both tables are relatively the same.
A B C D E
1 Store 1234 2345 3456 4567
2 1234 0 5 10 15
3 2345 5 0 20 25
4 3456 10 20 0 35
5 4567 15 25 35 0
It is basically a mileage table with location to location distance. I am looking for a way to take the values from the old table into the new when the row columns dont match up exactly due to new locations added.
I know how to do a vlookup, but that dosent do what Im looking for... I want a way for a formula or vba to something like "find Value in B2 "1234" where it intersects the value in D1 "2345" = D2 "5"
Should be able to do a Index and Match combo to find it. I1 = From, K1 = To you can just type in the locations into those cells and get the range out you want.
=INDEX(A1:E5, MATCH(I1,A1:E1,0), MATCH(K1,A1:A5,0))
Can you implement IF formula to vlookup? In abstract: =IF((vlookup)=something),do this, else)
I would be hapy to look into this issue further, if you could provide complete BEFORE data and expected AFTER data.
Also, maybe =DGET would work for you?
I used this formula slightly modified and it worked fine,
=INDEX($A$1:$G$7, MATCH(B12,$A$1:$A$7,0), MATCH(C12,$A$1:$G$1,0))
the first part of the equation is the entire table including the X and Y coords. the next two parts are the X and Y coords (you can swap these round if you wish)
so the requested information for x and y was put in cells C12 and B12 and all those cells below...
then I used the dollar symbol to fix all the other look up cells, so i could use auto fill, and entered this in E12 (this is where the result will appear.
You can see the table in the attached (or could if I was allowed to attach it). I am looking up B12 (3) in column A then looking up C12 (6) in row 1 and returning the value at the intersection (in this case returns "r").
or there would be an attachment if the stupid web page did not insist on having me obtain a 10 reputation... hopefully you get the idea...