0% found this document useful (0 votes)
12 views25 pages

Text, Nested If, Lookup Function

The document provides an overview of various Excel functions including TEXT functions like LEFT, MID, and RIGHT for extracting characters from text strings, as well as the IF function for conditional logic. It also covers the LOOKUP and HLOOKUP functions for retrieving data from arrays and tables. Each function is explained with its syntax, usage, and potential errors that may arise.

Uploaded by

2023444632
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views25 pages

Text, Nested If, Lookup Function

The document provides an overview of various Excel functions including TEXT functions like LEFT, MID, and RIGHT for extracting characters from text strings, as well as the IF function for conditional logic. It also covers the LOOKUP and HLOOKUP functions for retrieving data from arrays and tables. Each function is explained with its syntax, usage, and potential errors that may arise.

Uploaded by

2023444632
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

ASC454: ACTUARIAL

PROGRAMMING
TEXT, NESTED IF AND LOOKUP FUNCTION SYNTAX FUNCTION

Ms Sarah Nadirah Mohd Johari, 2021


EXTRACT INFORMATION FUNCTION SYNTAX
• Cateogrized under Excel TEXT functions.
• Will return a specified number of characters from the start of a given text
string.
• It can be used by combining it with other functions as well such as VALUE,
SUM, COUNT, DATE, DAY, etc

= 𝑳𝑬𝑭𝑻(𝒕𝒆𝒙𝒕, 𝒏𝒖𝒎 −𝒄𝒉𝒂𝒓𝒔 )

Ms Sarah Nadirah Mohd Johari, 2021


EXTRACT INFORMATION FUNCTION SYNTAX
• Cateogrized under Excel TEXT functions.
• Will return a specified number of characters from the middle of a given text
string.
• It can be used by combining it with other functions as well such as VALUE,
SUM, COUNT, DATE, DAY, etc

= 𝑴𝑰𝑫(𝒕𝒆𝒙𝒕, 𝒔𝒕𝒂𝒓𝒕 −𝒏𝒖𝒎, 𝒏𝒖𝒎 −𝒄𝒉𝒂𝒓𝒔 )

Ms Sarah Nadirah Mohd Johari, 2021


EXTRACT INFORMATION FUNCTION SYNTAX
• Cateogrized under Excel TEXT functions.
• Will return a specified number of characters from the end of a given text
string.
• It can be used by combining it with other functions as well such as VALUE,
SUM, COUNT, DATE, DAY, etc

= 𝑹𝑰𝑮𝑯𝑻(𝒕𝒆𝒙𝒕, 𝒏𝒖𝒎 −𝒄𝒉𝒂𝒓𝒔 )

Ms Sarah Nadirah Mohd Johari, 2021


EXTRACT INFORMATION FUNCTION SYNTAX
= 𝑳𝑬𝑭𝑻(𝒕𝒆𝒙𝒕, 𝒏𝒖𝒎 −𝒄𝒉𝒂𝒓𝒔 )
= 𝑴𝑰𝑫(𝒕𝒆𝒙𝒕, 𝒔𝒕𝒂𝒓𝒕 −𝒏𝒖𝒎, 𝒏𝒖𝒎 −𝒄𝒉𝒂𝒓𝒔 )
= 𝑹𝑰𝑮𝑯𝑻(𝒕𝒆𝒙𝒕, 𝒏𝒖𝒎 −𝒄𝒉𝒂𝒓𝒔 )
• Text (required argument) – original text string
• Num_chars (optional argument) - number of characters to be extracted, starting
from the left/right side of the text.
• start_chars (required argument) – This is an integer that specifies the position of
the first character that you want to be returned.
• Num_chars (required argument) - Specifies the number of characters, starting with
start_num, to be returned from the start of the given text. It is the number of
characters to be extracted.

Ms Sarah Nadirah Mohd Johari, 2021


EXTRACT INFORMATION FUNCTION SYNTAX
= 𝑳𝑬𝑭𝑻(𝒕𝒆𝒙𝒕, 𝒏𝒖𝒎 −𝒄𝒉𝒂𝒓𝒔 )
= 𝑴𝑰𝑫(𝒕𝒆𝒙𝒕, 𝒔𝒕𝒂𝒓𝒕 −𝒏𝒖𝒎, 𝒏𝒖𝒎 −𝒄𝒉𝒂𝒓𝒔 )
= 𝑹𝑰𝑮𝑯𝑻(𝒕𝒆𝒙𝒕, 𝒏𝒖𝒎 −𝒄𝒉𝒂𝒓𝒔 )
• #VALUE!error - Occurs if the given [num_chars] argument is less than 0.
• #VALUE!error - Occurs if the given [num_chars] argument is less than 0 or the
given start_num argument is less than 1.

Ms Sarah Nadirah Mohd Johari, 2021


IF FUNCTION SYNTAX
• Tests a given condition and returns one value for a TRUE result and another
value for a FALSE result.

OR

OR

SMALL OR MEDIUM OR LARGE

Ms Sarah Nadirah Mohd Johari, 2021


IF FUNCTION SYNTAX
= 𝑰𝑭(𝒍𝒐𝒈𝒊𝒄𝒂𝒍 −𝒕𝒆𝒔𝒕, 𝒗𝒂𝒍𝒖𝒆 −𝒊𝒇 −𝒕𝒓𝒖𝒆, 𝒗𝒂𝒍𝒖𝒆 −𝒊𝒇 −𝒇𝒂𝒍𝒔𝒆)

How to make nested if from the above syntax?

= 𝑰𝑭(𝒍𝒐𝒈𝒊𝒄𝒂𝒍 −𝒕𝒆𝒔𝒕, 𝒗𝒂𝒍𝒖𝒆 −𝒊𝒇 −𝒕𝒓𝒖𝒆, 𝑰𝑭(𝒍𝒐𝒈𝒊𝒄𝒂𝒍 −𝒕𝒆𝒔𝒕, 𝒗𝒂𝒍𝒖𝒆 −𝒊𝒇 −𝒕𝒓𝒖𝒆, 𝒗𝒂𝒍𝒖𝒆 −𝒊𝒇 −𝒇𝒂𝒍𝒔𝒆))

OR

= 𝑰𝑭(𝒍𝒐𝒈𝒊𝒄𝒂𝒍 −𝒕𝒆𝒔𝒕, 𝑰𝑭(𝒍𝒐𝒈𝒊𝒄𝒂𝒍 −𝒕𝒆𝒔𝒕, 𝒗𝒂𝒍𝒖𝒆 −𝒊𝒇 −𝒕𝒓𝒖𝒆, 𝒗𝒂𝒍𝒖𝒆 −𝒊𝒇 −𝒇𝒂𝒍𝒔𝒆), 𝒗𝒂𝒍𝒖𝒆 −𝒊𝒇 −𝒇𝒂𝒍𝒔𝒆)

Ms Sarah Nadirah Mohd Johari, 2021


IF FUNCTION SYNTAX
= 𝑰𝑭(𝒍𝒐𝒈𝒊𝒄𝒂𝒍 −𝒕𝒆𝒔𝒕, 𝒗𝒂𝒍𝒖𝒆 −𝒊𝒇 −𝒕𝒓𝒖𝒆, 𝑰𝑭(𝒍𝒐𝒈𝒊𝒄𝒂𝒍 −𝒕𝒆𝒔𝒕, 𝒗𝒂𝒍𝒖𝒆 −𝒊𝒇 −𝒕𝒓𝒖𝒆, 𝒗𝒂𝒍𝒖𝒆 −𝒊𝒇 −𝒇𝒂𝒍𝒔𝒆))

Is there any shortest syntax that can be used to replace nested if?

Yes, we can use lookup syntax.

Ms Sarah Nadirah Mohd Johari, 2021


LOOKUP FUNCTION SYNTAX
• Cateogrized under Excel Lookup and Reference functions.
• Performs a match lookup either in a one-row or one-column range and
returns the corresponding value from another one-row or one-column range.
• As financial analysis, if you wish to compare two rows or columns, you can use
the LOOKUP function and it is designed to handle the simplest cases of
vertical and horizontal lookup.
• Advanced versions of LOOKUP function are HLOOKUP and VLOOKUP.

= 𝑳𝑶𝑶𝑲𝑼𝑷(𝒍𝒐𝒐𝒌𝒖𝒑 −𝒗𝒂𝒍𝒖𝒆, 𝒍𝒐𝒐𝒌𝒖𝒑 −𝒗𝒆𝒄𝒕𝒐𝒓, 𝒓𝒆𝒔𝒖𝒍𝒕 _ 𝒗𝒆𝒄𝒕𝒐𝒓 )

Ms Sarah Nadirah Mohd Johari, 2021


LOOKUP FUNCTION SYNTAX
• Two forms of Lookup: Vector and Array.
• The vector form of the LOOKUP function will search one row or one column of
data for a specified value and then get the data from the same position in
another row or column.
• The array form of LOOKUP looks in the first row or column of an array for the
specified value and returns a value from the same position in the last row or
column of the array.
• use this form of LOOKUP when the values that we want to match are in the
first row or column of the array.

Ms Sarah Nadirah Mohd Johari, 2021


LOOKUP (VECTOR) FUNCTION SYNTAX
= 𝑳𝑶𝑶𝑲𝑼𝑷 𝒍𝒐𝒐𝒌𝒖𝒑 −𝒗𝒂𝒍𝒖𝒆, 𝒍𝒐𝒐𝒌𝒖𝒑 −𝒗𝒆𝒄𝒕𝒐𝒓, 𝒓𝒆𝒔𝒖𝒍𝒕 𝒗𝒆𝒄𝒕𝒐𝒓

• Lookup_value (required function) – value that we will be searching, and it can


be a logical value of TRUE or FALSE, reference to a cell, number or text.
• Lookup_vector (required function) – one-dimensional data that we wish to
search and need to sort it in ascending order first.
• Result_vector (required function) – An optional one-dimensional list of data
from which we want to return a value. If supplied, the [result_vector] must be
the same length as the lookup_vector.

Ms Sarah Nadirah Mohd Johari, 2021


LOOKUP (VECTOR) FUNCTION SYNTAX
= 𝑳𝑶𝑶𝑲𝑼𝑷 𝒍𝒐𝒐𝒌𝒖𝒑 −𝒗𝒂𝒍𝒖𝒆, 𝒂𝒓𝒓𝒂𝒚

• Lookup_value (required argument) – value that we will be searching.


• Array (required argument) – A range of cells that contains text, numbers, or
logical values that we want to compare with the lookup_value.

Ms Sarah Nadirah Mohd Johari, 2021


LOOKUP FUNCTION SYNTAX
• #N/Aerror - fails to find the closest match to the supplied lookup_value.
1. The smallest value in the lookup_vector is greater than the lookup_value
provided.
2. The lookup_vector is not in ascending order.
• #REF!error - Occurs if the formula is attempting to reference cells that are
non-existent.
1. Cells being deleted after the Lookup function has been entered.
2. Relative references in the Lookup function that have become invalid when
the functions have been copied to other cells.

Ms Sarah Nadirah Mohd Johari, 2021


EXERCISE IN CLASS
Given the following list of products, color, order id and quantity.

Ms Sarah Nadirah Mohd Johari, 2021


HLOOKUP FUNCTION SYNTAX
• Stands for Horizontal Lookup.
• used to retrieve information from a table by searching a row for the matching data and
outputting from the corresponding column

= 𝑯𝑳𝑶𝑶𝑲𝑼𝑷(𝒍𝒐𝒐𝒌𝒖𝒑 −𝒗𝒂𝒍𝒖𝒆, 𝒕𝒂𝒃𝒍𝒆 −𝒂𝒓𝒓𝒂𝒚, 𝒓𝒐𝒘 −𝒊𝒏𝒅𝒆𝒙 −𝒏𝒖𝒎, [𝒓𝒂𝒏𝒈𝒆 −𝒍𝒐𝒐𝒌𝒖𝒑])

Ms Sarah Nadirah Mohd Johari, 2021


HLOOKUP FUNCTION SYNTAX
= 𝑯𝑳𝑶𝑶𝑲𝑼𝑷(𝒍𝒐𝒐𝒌𝒖𝒑 −𝒗𝒂𝒍𝒖𝒆, 𝒕𝒂𝒃𝒍𝒆 −𝒂𝒓𝒓𝒂𝒚, 𝒓𝒐𝒘 −𝒊𝒏𝒅𝒆𝒙 −𝒏𝒖𝒎, [𝒓𝒂𝒏𝒈𝒆 −𝒍𝒐𝒐𝒌𝒖𝒑])

1. It is a case-insensitive lookup. Example: “TIM” and “tim” as the same.


2. The ‘Lookup_value’ should be the topmost row of the ‘table_array’ when using HLOOKUP. If
needed to look somewhere else, then we must use another Excel formula.
3. HLOOKUP supports wildcard characters such as ‘*’ or ‘?’ in the ‘lookup_value’ argument (only if
‘lookup_value’ is text).
4. #N/A error – It would be returned by HLOOKUP if ‘range_lookup’ is FALSE and the HLOOKUP
function is unable to find the ‘lookup_value’ in the given range.
5. If the ‘row_index_num’ < 1, HLOOKUP would return #VALUE! error. If ‘row_index_num’ > number
of columns in ‘table_array’, then it would give #REF! error.
6. Remember HLOOKUP function in Excel can return only one value. This would be the first value n
that matches the lookup value.

Ms Sarah Nadirah Mohd Johari, 2021


HLOOKUP FUNCTION SYNTAX
• #N/Aerror - fails to find the closest match to the supplied lookup_value.
1. The smallest value in the lookup_vector is greater than the lookup_value
provided.
2. The lookup_vector is not in ascending order.
• #REF!error - Occurs if the formula is attempting to reference cells that are
non-existent.
1. Cells being deleted after the Lookup function has been entered.
2. Relative references in the Lookup function that have become invalid when
the functions have been copied to other cells.

Ms Sarah Nadirah Mohd Johari, 2021


EXERCISE IN CLASS

Ms Sarah Nadirah Mohd Johari, 2021


VLOOKUP FUNCTION SYNTAX
• Stands for Vertical Lookup.
• VLOOKUP searches for the value in a column, HLOOKUP searches for the value in a row.

= 𝑽𝑳𝑶𝑶𝑲𝑼𝑷(𝒍𝒐𝒐𝒌𝒖𝒑 −𝒗𝒂𝒍𝒖𝒆, 𝒕𝒂𝒃𝒍𝒆 −𝒂𝒓𝒓𝒂𝒚, 𝒄𝒐𝒍 −𝒊𝒏𝒅𝒆𝒙 −𝒏𝒖𝒎, [𝒓𝒂𝒏𝒈𝒆 −𝒍𝒐𝒐𝒌𝒖𝒑])

Ms Sarah Nadirah Mohd Johari, 2021


VLOOKUP FUNCTION SYNTAX
= 𝑽𝑳𝑶𝑶𝑲𝑼𝑷(𝒍𝒐𝒐𝒌𝒖𝒑 −𝒗𝒂𝒍𝒖𝒆, 𝒕𝒂𝒃𝒍𝒆 −𝒂𝒓𝒓𝒂𝒚, 𝒄𝒐𝒍 −𝒊𝒏𝒅𝒆𝒙 −𝒏𝒖𝒎, [𝒓𝒂𝒏𝒈𝒆 −𝒍𝒐𝒐𝒌𝒖𝒑])

• Lookup_value (required argument) – value that we want to look up in the first column of a
table.
• Table_array (required argument) – The table array is the data array that is to be searched.
• Col_index_num (required argument) – an integer, specifying the column number of the
supplied table_array, that you want to return a value from.
• Range_lookup (optional argument) – can be set to TRUE or FALSE, which means:
TRUE – Approximate match, that is, if an exact match is not found, use the closest
match below the lookup_value.
FALSE – Exact match, that is, if an exact match not found, then it will return an error.

Ms Sarah Nadirah Mohd Johari, 2021


VLOOKUP FUNCTION SYNTAX
1. When range_lookup is omitted, the VLOOKUP function will allow a non-exact
match, but it will use an exact match if one exists.
2. The biggest limitation of the function is that it always looks right. It will get data
from the columns to the right of the first column in the table.
3. If the lookup column contains duplicate values, VLOOKUP will match the first
value only.
4. The function is not case-sensitive.
5. Suppose there’s an existing VLOOKUP formula in a worksheet. In that scenario,
formulas may break if we insert a column in the table. This is so because hard-
coded column index values don’t change automatically when columns are
inserted or deleted.

Ms Sarah Nadirah Mohd Johari, 2021


VLOOKUP FUNCTION SYNTAX
6. VLOOKUP allows the use of wildcards, e.g., an asterisk (*) or a question
mark (?).
7. Suppose in the table we are working with the function contains numbers
entered as text. If we are simply retrieving numbers as text from a column in
a table, it doesn’t matter. But if the first column of the table contains
numbers entered as text, we will get an #N/A! error if the lookup value is
not also in text form.
8. #N/A! error – Occurs if the VLOOKUP function fails to find a match to the
supplied lookup_value.

Ms Sarah Nadirah Mohd Johari, 2021


VLOOKUP FUNCTION SYNTAX
9. #REF! error – Occurs if either:
The col_index_num argument is greater than the number of columns in
the supplied table_array.
The formula attempted to reference cells that do not exist.
10. #VALUE! error – Occurs if either:
The col_index_num argument is less than 1 or is not recognized as a
numeric value.
The range_lookup argument is not recognized as one of the logical values
TRUE or FALSE.

Ms Sarah Nadirah Mohd Johari, 2021


EXERCISE EXTRACT PLACE OF BIRTH

Please use last week exercise data to simplify the nested if function in
order to extract information for place of birth.

Ms Sarah Nadirah Mohd Johari, 2021

You might also like