# How to match and set value in excel

I have two sheets in my workbook.

Sheet A contains two columns as student Id, student Name Sheet B contains student id,month name and some other columns too. student id is not unique in this sheet.

Now i want to add another column of student name(from sheet a) into sheet B, is it possible that i can write some formula for sheet B that compares the student id columns in both sheets and returns the student name (from sheet A)

-

## migrated from stackoverflow.comMay 18 '11 at 20:35

This question came from our site for professional and enthusiast programmers.

You need to use a `=VLOOKUP(lookup_value,table_array,col_index_num,range_lookup)`:

In sheet B put the following formulae (assuming your student ID is in column A-

``````=VLOOKUP(A1, Sheet1!A:B, 2, 0)
``````

The first A1 value is the cell that contains the student ID on sheet B. The Range (A:B) is the look table on the first sheet. The 2 is the column from the range (A:B) you want to return. The 0 is the true or false (0=false) this basically means EXACT match.

Hope this helps.

-

If Sheet1 has studentId in column A and name in column B Sheet2 has studentId in column A put this is column B in Sheet 2 (assuming you have a header row):

=IF(Sheet1!A2=A2,Sheet1!B2,)

Basically prepend your cell name with the sheet name and !

-
This only works if Column A is identical on both sheets -- unlikely, and not very useful since copy/paste would work in that case. – Excellll Jun 20 '11 at 21:12