Содержание
- How to Return Cell Address Instead of Value in Excel (Easy Formula)
- Lookup And Return Cell Address Using the ADDRESS Function
- Lookup And Return Cell Address Using the CELL Function
- Search Function in Excel
- Excel SEARCH Function
- SEARCH Formula in Excel
- Explanation
- How to Use the Search Function in excel? (with Examples)
- Example #1
- Example #2
- Example #3
- Example #4
- Things to Remember
- Search Function in Excel Video
- Recommended Articles
- Contact US
- Come Join Us!
- Posting Guidelines
- USING THE ‘WHERE’ CLAUSE IN EXCEL
- USING THE ‘WHERE’ CLAUSE IN EXCEL
- USING THE ‘WHERE’ CLAUSE IN EXCEL
- RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
- RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
- RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
- RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
- RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
- RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
- RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
- RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
- RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
- RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
- RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
- RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
- RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
- RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
- Red Flag Submitted
- Reply To This Thread
- Posting in the Tek-Tips forums is a member-only feature.
How to Return Cell Address Instead of Value in Excel (Easy Formula)
When using lookup formulas in Excel (such as VLOOKUP, XLOOKUP, or INDEX/MATCH), the intent is to find the matching value and get that value (or a corresponding value in the same row/column) as the result.
But in some cases, instead of getting the value, you may want the formula to return the cell address of the value.
This could be especially useful if you have a large data set and you want to find out the exact position of the lookup formula result.
There are some functions in Excel that designed to do exactly this.
In this tutorial, I will show you how you can find and return the cell address instead of the value in Excel using simple formulas.
This Tutorial Covers:
Lookup And Return Cell Address Using the ADDRESS Function
The ADDRESS function in Excel is meant to exactly this.
It takes the row and the column number and gives you the cell address of that specific cell.
Below is the syntax of the ADDRESS function:
- row_num: Row number of the cell for which you want the cell address
- column_num: Column number of the cell for which you want the address
- [abs_num]: Optional argument where you can specify whether want the cell reference to be absolute, relative, or mixed.
- [a1]: Optional argument where you can specify whether you want the reference in the R1C1 style or A1 style
- [sheet_text]: Optional argument where you can specify whether you want to add the sheet name along with the cell address or not
Now, let’s take an example and see how this works.
Suppose there is a dataset as shown below, where I have the Employee id, their name, and their department, and I want to quickly know the cell address that contains the department for employee id KR256.
Below is the formula that will do this:
In the above formula, I have used the MATCH function to find out the row number that contains the given employee id.
And since the department is in column C, I have used 3 as the second argument.
This formula works great, but it has one drawback – it won’t work if you add the row above the dataset or a column to the left of the dataset.
This is because when I specify the second argument (the column number) as 3, it’s hard-coded and won’t change.
In case I add any column to the left of the dataset, the formula would count 3 columns from the beginning of the worksheet and not from the beginning of the dataset.
So, if you have a fixed dataset and need a simple formula, this will work fine.
But if you need this to be more fool-proof, use the one covered in the next section.
Lookup And Return Cell Address Using the CELL Function
While the ADDRESS function was made specifically to give you the cell reference of the specified row and column number, there is another function that also does this.
It’s called the CELL function (and it can give you a lot more information about the cell than the ADDRESS function).
Below is the syntax of the CELL function:
- info_type: the information about the cell you want. This could be the address, the column number, the file name, etc.
- [reference]: Optional argument where you can specify the cell reference for which you need the cell information.
Now, let’s see an example where you can use this function to look up and get the cell reference.
Suppose you have a dataset as shown below, and you want to quickly know the cell address that contains the department for employee id KR256.
Below is the formula that will do this:
The above formula is quite straightforward.
I have used the INDEX formula as the second argument to get the department for the employee id KR256.
And then simply wrapped it within the CELL function and asked it to return the cell address of this value that I get from the INDEX formula.
Now here is the secret to why it works – the INDEX formula returns the lookup value when you give it all the necessary arguments. But at the same time, it would also return the cell reference of that resulting cell.
In our example, the INDEX formula returns “Sales” as the resulting value, but at the same time, you can also use it to give you the cell reference of that value instead of the value itself.
Normally, when you enter the INDEX formula in a cell, it returns the value because that is what it’s expected to do. But in scenarios where a cell reference is required, the INDEX formula will give you the cell reference.
In this example, that’s exactly what it does.
And the best part about using this formula is that it is not tied to the first cell in the worksheet. This means that you can select any data set (which could be anywhere in the worksheet), use the INDEX formula to do a regular look up and it would still give you the correct address.
And if you insert an additional row or column, the formula would adjust accordingly to give you the correct cell address.
So these are two simple formulas that you can use to look up and find and return the cell address instead of the value in Excel.
I hope you found this tutorial useful.
Other Excel tutorials you may also like:
Источник
Search Function in Excel
Excel SEARCH Function
The SEARCH function in Excel is categorized under text or string functions, but the output returned by this function is an integer. The SEARCH function gives us the position of a substring in a given string when we provide a parameter of the position to search from. Thus, this formula takes three arguments: substring, the string itself, and position to start the search.
For example, suppose we want to search the “Thank” substring in the provided text or string “Thank you.” Here, we need to find the “Thank” word using the SEARCH function, which will return the word “Thank” location.
=SEARCH(“Thank,” B8). The output will be 1.
The SEARCH function is a text function used to find the location of a substring in a string/text.
The SEARCH function can be used as a worksheet function. It is not case-sensitive.
Table of contents
SEARCH Formula in Excel
Below is the SEARCH formula in Excel.
Explanation
Excel SEARCH function has three-parameter two (find_text, within_text) are compulsory parameters and one (start_num) is optional.
Compulsory Parameter:
- find_text: find_text refers to the substring/character you want to search within a string or the text you want to find out.
- within_text:. Where your substring is located or where you perform the find_text.
Optional Parameter:
How to Use the Search Function in excel? (with Examples)
The SEARCH function is very simple and easy to use. Let us understand the working of the SEARCH function in some examples.
Example #1
Let us search the “Good” substring in the given text or string. Here, we have found the “Good” word using the SEARCH function, which will return the word “Good” location in the “Good morning.”
=SEARCH(“Good,” B6) and output will be 1.
Suppose two matches are found for “Good,” then SEARCH in Excel will give you the first match value. However, if you want the other good location, then you use the =SEARCH(“Good,” B7, 2) [start_num] as 2 then it will give you the place of the second match value, and the output will be 6.
Example #2
For first name=LEFT(B12,SEARCH(” “,B12)-1)
For last name=RIGHT(B12,LEN(B12)-SEARCH(” “,B12))
Example #3
Suppose there is a set of IDs. First, you have to find the _ location within IDs, then use Excel SEARCH to find the “_” location within IDs.
=SEARCH(“_,” B27), and output will be 6.
Example #4
Consider the table and search for the next 0 within the text A1-001-ID.
And start position will be 1, then =SEARCH(“?” &I8, J8, K8) output will be 3 because “?” neglects the one character before the 0, and output will be 3.
For the second row within a given table, the search result for A within B1-001-AY.
It will be 8, but if we use “*” in search, it will give you the 1 as location output because it will neglect all characters before “A,” and output will be 1 for it =SEARCH(“*” &I9, J9).
Similarly, for “J” 8 =SEARCH(I10,J10,K10) and 7 for =SEARCH(“?”&I10,J10,K10).
Similarly, for fourth row, the output will be 8 for =SEARCH(I11,J11,K11) and 1 for =SEARCH(“*” &I11,J11,K11)
Things to Remember
- It is not case-sensitive.
- It considers tanuj and TANUJ as the same value, which means it does not distinguish between lower and upper case.
- It is also allowed wildcard characters, i.e., “?”, “*,” and “
” tilde.
- “?” is used to find a single character.
- “*” is used for match sequences.
- If we want to search the “*” or”? “, we need to insert the “
” before the character.
- It returns the #VALUE! Error if there is no matching string is found in the within_text.
Suppose in the below example. We are searching for a substring “a” within the “Name” column. If found, it will return the location of a within name else. In addition, it will give a #VALUE error #VALUE Error #VALUE! Error in Excel represents that the reference cell the user has either entered an incorrect formula or used a wrong data type (mostly numerical data). Sometimes, it is difficult to identify the kind of mistake behind this error. read more , as shown below.
Search Function in Excel Video
Recommended Articles
This article is a guide to the SEARCH Function in Excel. Here, we discuss the SEARCH formula and how to use the SEARCH function, along with Excel examples and downloadable Excel templates. You may also look at these useful functions in Excel: –
Источник
Thanks. We have received your request and will respond promptly.
Come Join Us!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts - Keyword Search
- One-Click Access To Your
Favorite Forums - Automated Signatures
On Your Posts - Best Of All, It’s Free!
Posting Guidelines
Promoting, selling, recruiting, coursework and thesis posting is forbidden.
USING THE ‘WHERE’ CLAUSE IN EXCEL
USING THE ‘WHERE’ CLAUSE IN EXCEL
USING THE ‘WHERE’ CLAUSE IN EXCEL
New to the forum, can anyone tell me how I can use the where clause in a cell in excel. I have another sheet and a column called rowid. I would like to use this rule
SUMTOTAL OF CELLS WHERE ROWID = 21
Thxs in advance
RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
Three things are certain. Death, taxes and lost data. DPlank is to blame
Please read FAQ222-2244 before you ask a question
RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
Three things are certain. Death, taxes and lost data. DPlank is to blame
Please read FAQ222-2244 before you ask a question
RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
A B
1 Property Value Commission
2 100,000 7,000
3 200,000 14,000
4 300,000 21,000
5 400,000 28,000
Formula Description (Result)
=SUMIF(A2:A5,»>160000″,B2:B5) Sum of the commissions for property values over 160000 (63,000)
Three things are certain. Death, taxes and lost data. DPlank is to blame
Please read FAQ222-2244 before you ask a question
RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
Well I have a mixture of ids, on each case I would search on a criteria
IE: Equal to 21 for one row
equal to 31 for another, the sheet is a mixture of rowids so only certain ids ie: == 21 for one row in another sheet would apply, hope this makes sense
RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
Rather than speaking in riddles, please state your requrements in a clear, concise manner.
Skip,
Be advised: To be safe on the FOURTH, don’t take a FIFTH on the THIRD, or.
You might not come FORTH on the FIFTH!
RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
Sum of the values in B2:B100 WHERE the corresponding rowID in A2:A100 is 21 (Assuming 21 is numeric)
If the 21 is not numeric then it must be enclosed in quotes within the formula, eg
If you have a list of IDs in your spreadsheet in say cells J1:J5, and you wish to use this formula against each of those IDs in the list, then you can substitute the 21 or «21» for a cell reference, so in say K1 simply put the formula
and then copy down to K5. Note that the row part of the references have been made absolute with the use of the $ signs so that they don’t change when you copy down.
If this doesn’t help either then you need to give an example of your data, state what you want to get out of it, and give us the answer you would expect from the data you provide.
If you wish to sum on more than one criteria then investigate the SUMPRODUCT function in Help.
—————————————————————————-
It’s easier to beg forgiveness than ask permission
—————————————————————————-
RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
Need help finding an answer?
Try the Search Facility or read FAQ222-2244 on how to get better results.
RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
Give us the EXACT formulas you used when you tried it in the same sheet and also when you tried it against a different sheet. Don’t type them out, actually go into the cell and copy the formulas themselves and then paste into your note.
—————————————————————————-
It’s easier to beg forgiveness than ask permission
—————————————————————————-
RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
RE: USING THE ‘WHERE’ CLAUSE IN EXCEL
—————————————————————————-
It’s easier to beg forgiveness than ask permission
—————————————————————————-
Red Flag Submitted
Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.
Reply To This Thread
Posting in the Tek-Tips forums is a member-only feature.
Click Here to join Tek-Tips and talk with other members! Already a Member? Login
Источник
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS
Contact US
Thanks. We have received your request and will respond promptly.
Log In
Come Join Us!
Are you a
Computer / IT professional?
Join Tek-Tips Forums!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts - Keyword Search
- One-Click Access To Your
Favorite Forums - Automated Signatures
On Your Posts - Best Of All, It’s Free!
*Tek-Tips’s functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.
Posting Guidelines
Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Students Click Here
USING THE ‘WHERE’ CLAUSE IN EXCELUSING THE ‘WHERE’ CLAUSE IN EXCEL(OP) 1 Jul 05 04:19 Hi New to the forum, can anyone tell me how I can use the where clause in a cell in excel… I have another sheet and a column called rowid… I would like to use this rule SUMTOTAL OF CELLS WHERE ROWID = 21 Thxs in advance Red Flag SubmittedThank you for helping keep Tek-Tips Forums free from inappropriate posts. |
Join Tek-Tips® Today!
Join your peers on the Internet’s largest technical computer professional community.
It’s easy to join and it’s free.
Here’s Why Members Love Tek-Tips Forums:
- Talk To Other Members
- Notification Of Responses To Questions
- Favorite Forums One Click Access
- Keyword Search Of All Posts, And More…
Register now while it’s still free!
Already a member? Close this window and log in.
Join Us Close
I want to return rows from a table, where certain conditions are met, in excel.
ProdGroup Width (mm) Diameter (mm) Date
Prod1 1120 1000 2016-01-11
Prod2 600 1000 2017-10-18
Prod1 930 800 2015-04-11
Prod3 1250 1200 2016-04-18
Prod2 840 1000 2019-06-27
Prod2 840 900 2018-03-21
I want to be make an equivalent of: «SELECT * FROM Table WHERE ProdGroup = «Prod2″ AND Diameter = 1000»
in excel. My idea is that I enter the values into two cells and that rows are returned based on what I write in the two cells.
I have tried using the =INDEX() function but I only managed to search for rows matching only 1 condition. Furthermore, I only succeeded return one row.
=INDEX(B2:D6,MATCH(A10,A2:A6,0),1)
This only gives me one IN parameter. With Prod2 this would only return one row.
With inputs «Prod2» and 1000:
ProdGroup Diameter
Prod2 1000
I want an outcome like this:
Prod2 600 1000 2017-12-18
Prod2 840 1000 2019-06-27
I have no idea on how to go about doing this. Can somebody please help?
Kind regards
pbdude
26 Sep ’22 by Antonio Nakić-Alfirević
SQL Query function in Excel
If you’re reading this article you probably know that Google Sheets has a QUERY function that allows you to run SQL-like queries against data in the sheet. This function lets you do all sorts of gymnastics with the data in your sheet, be it filtering, aggregating, or pivoting data.
Being a fully-fledged desktop app, Excel tends to be more feature-rich than Google Sheets. This is especially true in the data analytics department where Excel shines with advanced Excel functions as well as Power Query functionality.
However, Excel doesn’t natively have a QUERY function that you can use in cells on the sheet.
In this blog post, I’m going to show you how to add a QUERY function to Excel and give a few examples of how to use it.
First look
Let’s start by taking a look at the function in action.
The function is pretty straightforward. It accepts the SQL query as the first parameter and returns a table with the results of the query.
The results automatically spill to the necessary amount of space. This spilling behavior relies on the dynamic array functionality that’s available in Excel 365 (but isn’t in earlier versions of Microsoft Excel).
Works with Excel tables
In Google Sheets, the QUERY function references data by address (e.g. “A1:B10”) while columns are referenced by letters (e.g. A, B, C…).
This works but has some drawbacks:
- It makes the query sensitive to the location of the data. If the data is moved or if columns are reordered, the query will break.
- It makes the query difficult to read since it uses range addresses and column letters instead of table and column names (e.g. Employees, DateOfBirth…)
- Adding or removing rows can break the query. For example, if the provided range is “A1:H10” the query will only take into account the first 10 rows. If additional rows are added, the query will not take them into account. You can get around this by omitting the end row number (e.g. “A1:H”), but this means that there must be no other content below the data range.
Excel, on the other hand, allows explicitly defining tables (aka ListObjects) that delineate the areas that hold data. Each Excel table has a name, as do its columns. This makes Excel tables very similar to database tables and makes them easier to work with from SQL.
Full SQL syntax support (SQLite)
Under the hood, the Windy.Query function is powered by SQLite – a small but powerful embedded database engine.
When called, the function passes the query to the built-in SQLite engine which has an adapter that lets it use Excel tables as its data source.
This means that the entire SQLite syntax is available for use in queries. In comparison, in Google Sheets, the query syntax is rather limited. It only supports a single table (no joins) and a very small set of built-in functions.
Examples of use
Since the engine under the hood is SQLite, queries can use all operations available in SQLite, including table joins, temp tables, column table expressions, window functions etc… Let’s go over some examples of how to use these in Excel.
Joining tables
Here’s an example of a simple one-to-many join:
The usual way of doing a simple operation such as this one in Excel would be to use xlookup or PowerQuery, but SQL is now another option. And if we needed anything more complex than a simple join, SQL would quickly shine as the most powerful and convenient option of the three.
Merging table rows (union)
Another way we might want to combine two (or more) tables is to combine their rows. We can do this with a SQL UNION operator.
The tables might have some rows in common. If we want to keep only one instance of such rows we would use the regular UNION operator. If we want to keep both versions of rows that are in common, we would use the UNION ALL operator.
Finding differences between two tables
In the previous example, we had two tables that had some rows in common and some rows not. Let’s assume, for example, that the first table contains last year’s list of employees and the second table is the new list of employees.
If we wanted to find out the differences between the two tables, we could easily do that with a bit of SQL.
All of the rows that are in the first table but not in the second one we will mark as “deleted”. All of the rows that are in the second table but not in the first one we will mark as “added”. Here’s what that SQL query looks like:
select id, name, 'deleted' from employees e where not exists (select * from Employees_New en where e.id == en.Id) union select id, name, 'added' from employees_new en where not exists (select * from Employees e where e.id == en.Id)
And here’s what the result looks like:
Ranking rows
Another useful thing we might want to do is rank rows based on some criteria. For example, suppose we have a table with a list of cities. For each city we have its population and the country it belongs to.
Our task is to find the top 3 cities in each country based on population. Here’s how we might do that in SQL.
-- we use this CTE so we can reference the calculated 'rank_pop' column in the where clause with cte as ( select city, country, population, -- using the RANK() window function RANK() OVER (PARTITION BY country ORDER BY population) as rank_pop from cities c) select * from cte where -- filtering by the 'rank_pop' column from the CTE rank_pop <= 3 order by country, rank_pop
This query is a bit more complex than the previous ones. It uses a common table expression and a window function (the rank function), and showcases the ability to write complex SQL in queries.
Queries can also make use of dozens of built-in SQLite functions. Various specialized extended functions such as RegexReplace, GPSDist (GPS distance between two points) and LevDist (fuzzy text matching) are also available.
Updating tables
OK, this next example is a bit of a hack, but a useful one… The query you supply doesn’t need to be a SELECT query. You can do UPDATE/INSERT/DELETE statements as well, and these will modify the data in the target Excel tables.
This can be a handy way to clean and transform data in your tables in place, without having to export/import the data to an external database (e.g. SQL Server, MySql, Postgres…).
This works because the SQLite engine isn’t copying the data. Rather, it’s using an adapter that lets it access live data in the Excel table.
How does the function see Excel tables?
At first glance, it might seem strange that the query can access your workbook tables. After all, we did not pass them in as parameters, and functions normally only work with parameters that are passed to them.
However, the Windy.Query function is aware of the workbook it’s being called from and it can read data from the workbook’s tables without the need for passing them in as parameters. This makes the function much easier to call especially when working with multiple tables.
Column Headers
Results returned by the Windy.Query function can optionally include headers. This is controlled by the second parameter of the function.
The texts in the column headers are determined by the SQL query itself. You can easily rename result columns by aliasing them in the select list.
Automatically refresh results
By default, the SQL query runs as a one-off operation when you enter the formula but does not refresh if the source tables change. However, if you want the query to refresh whenever one of the source tables changes, you can easily do so by setting the autoRefresh argument to true.
Note that the auto-refresh functionality relies on Excel’s RTD (Real-Time Data) server. The RTD server usually throttles updates so functions don’t overwhelm Excel with frequent updates. The default throttle interval is 2s meaning that the function will not update more than once every 2s. To improve responsiveness, you can lower this value to something like 20ms. The simplest way to do this is through the “Configure” dialog in the QueryStorm runtime’s ribbon.
Passing parameters
When needed, SQL queries can use values from cells as parameters. To use a cell as a parameter in a query, start by giving the cell a name (named range).
Once the cell has a name, you can reference it in the query using the @paramName or $paramName syntax.
If automatic refresh is turned on, results will automatically refresh whenever one of the parameter cells changes its value.
Performance
This is all well and good for small tables, you might think, but how does it handle large data sets? Well, it handles them quite well. The function can read source tables of 100k rows and 10 columns within a few milliseconds and can return this amount of data in a second or two. In addition to this, all columns are automatically indexed so searches and joins are extremely performant as well.
This makes the function perform very well, both from the data throughput standpoint as well as from the computational one.
OK, so is this better than the Google Sheets version of the QUERY function?
Yes, dah. Did you read the previous chapters? 😛
Installing the Windy.Query function
So how do you install this function into your Excel? It’s a simple 2-step process.
Step 1 is to install the QueryStorm Runtime add-in (if you don’t already have it). This is a free, 4MB add-in for Excel that lets you install and use various extensions for Excel. It’s basically an app store for Excel.
Step 2 is to click the “Extensions” button in the “QueryStorm” tab in the Excel ribbon, find the Windy.Query package in the “Online” tab, and install it.
What happens if I share the workbook with a user who doesn’t have the function?
Nothing bad. If the other user doesn’t have the function installed, they will see the last results of the query that were returned on your machine. They just won’t be able to refresh the results.
Advanced SQL query editor
Writing SQL queries in the formula bar can get a bit unwieldy. To make queries easier to write, it’s better to use a proper editor, preferably one that offers syntax highlighting and code completion for SQL and knows about the tables in your workbook.
For this purpose, I recommend using the QueryStorm IDE. This is an advanced IDE that lets you use SQL in Excel. You can write the query in the QueryStorm code editor and then paste the query into the Windy.Query function when you’re happy with it (if needed).
The IDE does more than just allow using SQL in Excel. You can use it to create and share functions and addins for Excel. In fact the QueryStorm IDE was used to create the Windy.Query function itself.
The IDE has a free community version for individuals and small companies, while users in larger companies can make use of the free trial license. For paid licenses, check out the pricing page.
You can read more in this blog post that’s dedicated to the QueryStorm SQL IDE.
Video demonstration
For a video demonstration of the Windy.Query function, take a look the following video:
Summary
This step-by-step article describes how to find data in a table (or range of cells) by using various built-in functions in Microsoft Excel. You can use different formulas to get the same result.
Create the Sample Worksheet
This article uses a sample worksheet to illustrate Excel built-in functions. Consider the example of referencing a name from column A and returning the age of that person from column C. To create this worksheet, enter the following data into a blank Excel worksheet.
You will type the value that you want to find into cell E2. You can type the formula in any blank cell in the same worksheet.
A |
B |
C |
D |
E |
||
1 |
Name |
Dept |
Age |
Find Value |
||
2 |
Henry |
501 |
28 |
Mary |
||
3 |
Stan |
201 |
19 |
|||
4 |
Mary |
101 |
22 |
|||
5 |
Larry |
301 |
29 |
Term Definitions
This article uses the following terms to describe the Excel built-in functions:
Term |
Definition |
Example |
Table Array |
The whole lookup table |
A2:C5 |
Lookup_Value |
The value to be found in the first column of Table_Array. |
E2 |
Lookup_Array |
The range of cells that contains possible lookup values. |
A2:A5 |
Col_Index_Num |
The column number in Table_Array the matching value should be returned for. |
3 (third column in Table_Array) |
Result_Array |
A range that contains only one row or column. It must be the same size as Lookup_Array or Lookup_Vector. |
C2:C5 |
Range_Lookup |
A logical value (TRUE or FALSE). If TRUE or omitted, an approximate match is returned. If FALSE, it will look for an exact match. |
FALSE |
Top_cell |
This is the reference from which you want to base the offset. Top_Cell must refer to a cell or range of adjacent cells. Otherwise, OFFSET returns the #VALUE! error value. |
|
Offset_Col |
This is the number of columns, to the left or right, that you want the upper-left cell of the result to refer to. For example, «5» as the Offset_Col argument specifies that the upper-left cell in the reference is five columns to the right of reference. Offset_Col can be positive (which means to the right of the starting reference) or negative (which means to the left of the starting reference). |
Functions
LOOKUP()
The LOOKUP function finds a value in a single row or column and matches it with a value in the same position in a different row or column.
The following is an example of LOOKUP formula syntax:
=LOOKUP(Lookup_Value,Lookup_Vector,Result_Vector)
The following formula finds Mary’s age in the sample worksheet:
=LOOKUP(E2,A2:A5,C2:C5)
The formula uses the value «Mary» in cell E2 and finds «Mary» in the lookup vector (column A). The formula then matches the value in the same row in the result vector (column C). Because «Mary» is in row 4, LOOKUP returns the value from row 4 in column C (22).
NOTE: The LOOKUP function requires that the table be sorted.
For more information about the LOOKUP function, click the following article number to view the article in the Microsoft Knowledge Base:
How to use the LOOKUP function in Excel
VLOOKUP()
The VLOOKUP or Vertical Lookup function is used when data is listed in columns. This function searches for a value in the left-most column and matches it with data in a specified column in the same row. You can use VLOOKUP to find data in a sorted or unsorted table. The following example uses a table with unsorted data.
The following is an example of VLOOKUP formula syntax:
=VLOOKUP(Lookup_Value,Table_Array,Col_Index_Num,Range_Lookup)
The following formula finds Mary’s age in the sample worksheet:
=VLOOKUP(E2,A2:C5,3,FALSE)
The formula uses the value «Mary» in cell E2 and finds «Mary» in the left-most column (column A). The formula then matches the value in the same row in Column_Index. This example uses «3» as the Column_Index (column C). Because «Mary» is in row 4, VLOOKUP returns the value from row 4 in column C (22).
For more information about the VLOOKUP function, click the following article number to view the article in the Microsoft Knowledge Base:
How to Use VLOOKUP or HLOOKUP to find an exact match
INDEX() and MATCH()
You can use the INDEX and MATCH functions together to get the same results as using LOOKUP or VLOOKUP.
The following is an example of the syntax that combines INDEX and MATCH to produce the same results as LOOKUP and VLOOKUP in the previous examples:
=INDEX(Table_Array,MATCH(Lookup_Value,Lookup_Array,0),Col_Index_Num)
The following formula finds Mary’s age in the sample worksheet:
=INDEX(A2:C5,MATCH(E2,A2:A5,0),3)
The formula uses the value «Mary» in cell E2 and finds «Mary» in column A. It then matches the value in the same row in column C. Because «Mary» is in row 4, the formula returns the value from row 4 in column C (22).
NOTE: If none of the cells in Lookup_Array match Lookup_Value («Mary»), this formula will return #N/A.
For more information about the INDEX function, click the following article number to view the article in the Microsoft Knowledge Base:
How to use the INDEX function to find data in a table
OFFSET() and MATCH()
You can use the OFFSET and MATCH functions together to produce the same results as the functions in the previous example.
The following is an example of syntax that combines OFFSET and MATCH to produce the same results as LOOKUP and VLOOKUP:
=OFFSET(top_cell,MATCH(Lookup_Value,Lookup_Array,0),Offset_Col)
This formula finds Mary’s age in the sample worksheet:
=OFFSET(A1,MATCH(E2,A2:A5,0),2)
The formula uses the value «Mary» in cell E2 and finds «Mary» in column A. The formula then matches the value in the same row but two columns to the right (column C). Because «Mary» is in column A, the formula returns the value in row 4 in column C (22).
For more information about the OFFSET function, click the following article number to view the article in the Microsoft Knowledge Base:
How to use the OFFSET function