Xu Hướng 4/2023 # How To Use The Excel Vlookup Function # Top 7 View | Hoisinhvienqnam.edu.vn

Xu Hướng 4/2023 # How To Use The Excel Vlookup Function # Top 7 View

Bạn đang xem bài viết How To Use The Excel Vlookup Function được cập nhật mới nhất trên website Hoisinhvienqnam.edu.vn. Hy vọng những thông tin mà chúng tôi đã chia sẻ là hữu ích với bạn. Nếu nội dung hay, ý nghĩa bạn hãy chia sẻ với bạn bè của mình và luôn theo dõi, ủng hộ chúng tôi để cập nhật những thông tin mới nhất.

VLOOKUP is an Excel function to get data from a table organized vertically. Lookup values must appear in the first column of the table passed into VLOOKUP.  VLOOKUP supports approximate and exact matching, and wildcards (* ?) for partial matches. 

V is for vertical

The purpose of VLOOKUP is to get information from a table organized like this:

Using the Order number in column B as a lookup value, VLOOKUP can get the Customer ID, Amount, Name, and State for any order. For example, to get the customer name for order 1004, the formula is:

=

VLOOKUP

(

1004

,

B5:F9

,

4

,

FALSE

)

// returns "Sue Martin"

For horizontal data, you can use the HLOOKUP, INDEX and MATCH, or XLOOKUP.

VLOOKUP is based on column numbers

When you use VLOOKUP, imagine that every column in the table is numbered, starting from the left. To get a value from a particular column, provide the appropriate number as the “column index”. For example, the column index to retrieve the first name below is 2:

The last name and email can be retrieved with columns 3 and 4:

=

VLOOKUP

(

H3

,

B4:E13

,

2

,

FALSE

)

// first name

=

VLOOKUP

(

H3

,

B4:E13

,

3

,

FALSE

)

// last name

=

VLOOKUP

(

H3

,

B4:E13

,

4

,

FALSE

)

// email address

VLOOKUP only looks right

VLOOKUP can only look to the right. The data you want to retrieve (result values) can appear in any column to the right of the lookup values:

If you need to lookup values to the left, see INDEX and MATCH, or XLOOKUP.

Exact and approximate matching

VLOOKUP has two modes of matching, exact and approximate. The name of the argument that controls matching is “range_lookup“. This is a confusing name, because it seems to have something to do with cell ranges like A1:A10. Actually, the word “range” in this case refers to “range of values” – when range_lookup is TRUE, VLOOKUP will match a range of values rather than an exact value. A good example of this is using VLOOKUP to calculate grades.

It is important to understand that range_lookup defaults to TRUE, which means VLOOKUP will use approximate matching by default, which can be dangerous. Set range_lookup to FALSE to force exact matching:

=

VLOOKUP

(

value

,

table

,

col_index

)

// approximate match (default)

=

VLOOKUP

(

value

,

table

,

col_index

,

TRUE

)

// approximate match

=

VLOOKUP

(

value

,

table

,

col_index

,

FALSE

)

// exact match

Note: You can also supply zero (0) instead of FALSE for an exact match.

Exact match

In most cases, you’ll probably want to use VLOOKUP in exact match mode. This makes sense when you have a unique key to use as a lookup value, for example, the movie title in this data:

The formula in H6 to find Year, based on an exact match of movie title, is:

=

VLOOKUP

(

H4

,

B5:E9

,

2

,

FALSE

)

// FALSE = exact match

Approximate match

In cases when you want the best match, not necessarily an exact match, you’ll want to use approximate mode. For example, below we want to look up a commission rate in the table G5:H10. The lookup values come from column C. In this example, we need to use VLOOKUP in approximate match mode, because in most cases an exact match will never be found. The VLOOKUP formula in D5 is configured to perform an approximate match by setting the last argument to TRUE:

=

VLOOKUP

(

C5

,

$G$5:$H$10

,

2

,

TRUE

)

// TRUE = approximate match

VLOOKUP will scan values in column G for the lookup value. If an exact match is found, VLOOKUP will use it. If not, VLOOKUP will “step back” and match the previous row.

Note: data must be sorted in ascending order by lookup value when you use approximate match mode with VLOOKUP.

First match

=

VLOOKUP

(

E5

,

B5:C11

,

2

,

FALSE

)

// returns 17

Wildcard match

The VLOOKUP function supports wildcards, which makes it possible to perform a partial match on a lookup value. For instance, you can use VLOOKUP to retrieve values from a table after typing in only part of a lookup value. To use wildcards with VLOOKUP, you must specify the exact match mode by providing FALSE or 0 for the last argument, range_lookup. The formula in H7 retrieves the first name, “Michael”, after typing “Aya” into cell H4:

=

VLOOKUP

(

$H$4

&

"*"

,

$B$5:$E$104

,

2

,

FALSE

)

Read a more detailed explanation here.

Two-way lookup

Inside the VLOOKUP function, the column index argument is normally hard-coded as a static number.  However, you can also create a dynamic column index by using the MATCH function to locate the right column. This technique allows you to create a dynamic two-way lookup, matching on both rows and columns. In the screen below, VLOOKUP is configured to perform a lookup based on Name and Month. The formula in H6 is:

=

VLOOKUP

(

H4

,

B5:E13

,

MATCH

(

H5

,

B4:E4

,

0

),

0

)

For more details, see this example.

Note: In general, INDEX and MATCH is a more flexible way to perform two-way lookups.

Multiple criteria

The VLOOKUP function does not handle multiple criteria natively. However, you can use a helper column to join multiple fields together, and use these fields like multiple criteria inside VLOOKUP.  In the example below, Column B is a helper column that concatenates first and last names together with this formula:

=

C5

&

D5

// helper column

VLOOKUP is configured to do the same thing to create a lookup value. The formula in H6 is:

=

VLOOKUP

(

H4

&

H5

,

B5:E13

,

4

,

0

)

For details, see this example.

Note: INDEX and MATCH and XLOOKUP are more robust ways to handle lookups based on multiple criteria.

VLOOKUP and #N/A errors

If you use VLOOKUP you will inevitably run into the #N/A error. The #N/A error just means “not found”. For example, in the screen below, the lookup value ”Toy Story 2″ does not exist in the lookup table, and all three VLOOKUP formulas return #N/A:

One way to “trap” the NA error is to use the IFNA function like this:

The formula in H6 is:

=

IFNA

(

VLOOKUP

(

H4

,

B5:E9

,

2

,

FALSE

),

"Not found"

)

The message can be customized as desired. To return nothing (i.e. to display a blank result) when VLOOKUP returns #N/A you can use an empty string like this:

=

IFNA

(

VLOOKUP

(

H4

,

B5:E9

,

2

,

FALSE

),

""

)

// no message

The #N/A error is useful because it tells you something is wrong.  In practice, there are many reasons why you might see this error, including:

The lookup value does not exist in the table

The lookup value is misspelled, or contains extra space

Match mode is exact, but should be approximate

The table range is not entered correctly

You are copying VLOOKUP, and the table reference is not locked

Read more: VLOOKUP without #N/A errors 

More about VLOOKUP

Other notes

Range_lookup controls whether value needs to match exactly or not. The default is TRUE = allow non-exact match.

Set range_lookup to FALSE to require an exact match and TRUE to allow a non-exact match.

If range_lookup is TRUE (the default setting), a non-exact match will cause the VLOOKUP function to match the nearest value in the table that is still less than value.

When range_lookup is omitted, the VLOOKUP function will allow a non-exact match, but it will use an exact match if one exists.

If range_lookup is TRUE (the default setting) make sure that lookup values in the first row of the table are sorted in ascending order. Otherwise, VLOOKUP may return an incorrect or unexpected value.

If range_lookup is FALSE (require exact match), values in the first column of table do not need to be sorted.

How To Use The Excel Roundup Function

The ROUNDUP function works like the ROUND function, except the ROUNDUP function will always round numbers up. The number of places to round to is controlled by the num_digits argument. Positive numbers round to the right of the decimal point, negative numbers round to the left, and zero rounds to the nearest 1. The table below summarizes this behavior:

Digits Behavior

Round up to nearest .1, .01, .001, etc.

Round up to nearest 10, 100, 1000, etc.

=0 Round up to nearest 1

Example #1 – round to right

To round up values to the right of the decimal point, use a positive number for digits:  

=

ROUNDUP

(

A1

,

1

)

// Round up to 1 decimal place

=

ROUNDUP

(

A1

,

2

)

// Round up to 2 decimal places

=

ROUNDUP

(

A1

,

3

)

// Round up to 3 decimal places

=

ROUNDUP

(

A1

,

4

)

// Round up to 4 decimal places

Example #2 – round to left

To round up values to the left of the decimal point, use zero or a negative number for digits:  

=

ROUNDUP

(

A1

,

0

)

// Round up to nearest whole number

=

ROUNDUP

(

A1

,

-

1

)

// Round up to nearest 10

=

ROUNDUP

(

A1

,

-

2

)

// Round up to nearest 100

=

ROUNDUP

(

A1

,

-

3

)

// Round up to nearest 1000

=

ROUNDUP

(

A1

,

-

4

)

// Round up to nearest 10000

Example #3 – nesting

Other operations and functions can be nested inside the ROUNDUP function. For example, to round the result of A1 divided by B1, you can use a formula like this:

=

ROUNDUP

(

A1

/

B1

,

0

)

// round up result to nearest whole number

Rounding functions in Excel

To round normally, use the ROUND function.

To round to the nearest multiple, use the MROUND function.

To round down to the nearest specified place, use the ROUNDDOWN function.

To round down to the nearest specified multiple, use the FLOOR function.

To round up to the nearest specified place, use the ROUNDUP function.

To round up to the nearest specified multiple, use the CEILING function.

To round down and return an integer only, use the INT function.

To truncate decimal places, use the TRUNC function.

How To Use The Excel Timevalue Function

Sometimes, times in Excel appear as text values that are not recognized properly as time. The TIMEVALUE function is meant to parse a time that appears as a text value into a valid Excel time. A native Excel time is more useful than text because it is a numeric value that can be formatted as time and directly manipulated in a formula.

The TIMEVALUE function takes just one argument, called time_text. If time_text is a cell address, the value in the cell must be text. If time_text is entered directly into the formula it must be enclosed in double quotes (“”). Time_text should be supplied in a text format that Excel can recognize, for example, “6:45 PM” or “18:45”. TIMEVALUE ignores dates if present in a text string. 

The TIMEVALUE function creates a time in serial number format from a date and/or time in an Excel text format. TIMEVALUE will return a decimal number between 0 and 0.99988426, representing 12:00:00 AM to 11:59:59 PM. Because the maximum value returned by TIMEVALUE is less than 1, hours will reset every 24 hours (like a clock).

Examples

The formulas below show the output from TIMEVALUE:

=

TIMEVALUE

(

"12:00"

)

// returns 0.5

=

TIMEVALUE

(

"12:00 PM"

)

// returns 0.5

=

TIMEVALUE

(

"18:00"

)

// returns 0.75

To display the output from TIMEVALUE as a formatted time, apply a time number format.

Alternative formula

Notice that the TIMEVALUE formula in C15 fails with a #VALUE! error, because cell B15 already contains a valid time. This is a limitation of the TIMEVALUE function. If you have a mix of valid and invalid dates, you can use the simple formula below as an alternative:

=

A1

+

0

The math operation of adding zero will cause Excel will try to coerce the value in A1 to a number. If Excel is able parse the text into a proper time it will return a valid time as a decimal number. If the time is already a valid Excel time, adding zero will have no effect, and generate no error.

Notes

TIMEVALUE will return a #VALUE error if time_text does not contain time formatted as text.

Ms Excel: How To Use The If

This Excel tutorial explains how to use the Excel IF-THEN-ELSE statement (in VBA) with syntax and examples.

Description

The Microsoft Excel IF-THEN-ELSE statement can only be used in VBA code. It executes one set of code if a specified condition evaluates to TRUE, or another set of code if it evaluates to FALSE.

The IF-THEN-ELSE statement is a built-in function in Excel that is categorized as a Logical Function. It can be used as a VBA function (VBA) in Excel. As a VBA function, you can use this function in macro code that is entered through the Microsoft Visual Basic Editor.

Please read our IF function (WS) page if you are looking for the worksheet version of the IF statement as it has a very different syntax.

Download Example

Syntax

The syntax for the IF-THEN-ELSE statement in Microsoft Excel is:

If condition_1 Then result_1 ElseIf condition_2 Then result_2 ... ElseIf condition_n Then result_n Else result_else End If

Parameters or Arguments

condition_1, condition_2, … condition_n The conditions that are to be evaluated in the order listed. Once a condition is found to be true, the corresponding code will be executed. No further conditions will be evaluated. result_1, result_2, … result_n The code that is executed once a condition is found to be true. result_else The code that is executed when all previous conditions (condition1, condition2, … condition_n) are false.

Returns

The IF-THEN-ELSE statement evaluates the conditions in the order listed. It will execute the corresponding code when a condition is found to be true. If no condition is met, then the Else portion of the IF-THEN-ELSE statement will be executed.

Note

Applies To

Excel for Office 365, Excel 2019, Excel 2016, Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000

Example (as VBA Function)

The IF-THEN-ELSE statement can only be used in VBA code in Microsoft Excel.

Let’s look at some Excel IF-THEN-ELSE statement function examples and explore how to use the IF-THEN-ELSE statement in Excel VBA code:

First, let’s look at a simple example.

If LRegion ="N" Then LRegionName = "North" End If

Next, let’s look at an example that uses ElseIf.

If LRegion ="N" Then LRegionName = "North" ElseIf LRegion = "S" Then LRegionName = "South" ElseIf LRegion = "E" Then LRegionName = "East" ElseIf LRegion = "W" Then LRegionName = "West" End If

Finally, let’s look at an example that uses Else.

If LRegion ="N" Then LRegionName = "North" ElseIf LRegion = "S" Then LRegionName = "South" ElseIf LRegion = "E" Then LRegionName = "East" Else LRegionName = "West" End If

Example#1 from Video

In the first video example, we are going to use the IF-THEN-ELSE statement to update cell C2 with “North”, “South”, “East” or “West” depending on the region code entered in cell A2.

So if we entered “N” in cell A2, we want “North” to appear in cell C2. If we entered “S” in cell A2, we want “South” to appear in cell C2, and so on.

Sub totn_if_example1() Dim LRegion As String Dim LRegionName As String LRegion = Range("A2").Value If LRegion = "N" Then LRegionName = "North" ElseIf LRegion = "S" Then LRegionName = "South" ElseIf LRegion = "E" Then LRegionName = "East" Else LRegionName = "West" End If Range("C2").Value = LRegionName End Sub

Example#2 from Video

Sub totn_if_example2() For Each grade In Range("B2:B8") If grade = "A" Or grade = "B" Then grade.Offset(0, 1).Value = "Great work" ElseIf grade = "C" Then grade.Offset(0, 1).Value = "Needs Improvement" Else grade.Offset(0, 1).Value = "Time for a Tutor" End If Next grade End Sub

Cập nhật thông tin chi tiết về How To Use The Excel Vlookup Function trên website Hoisinhvienqnam.edu.vn. Hy vọng nội dung bài viết sẽ đáp ứng được nhu cầu của bạn, chúng tôi sẽ thường xuyên cập nhật mới nội dung để bạn nhận được thông tin nhanh chóng và chính xác nhất. Chúc bạn một ngày tốt lành!