0% found this document useful (0 votes)
49 views55 pages

Lab 7

This document provides instructions for using various Excel functions and tools including creating tables, removing duplicate values, budgeting, date validation, drop-down lists, counting numeric or text values, using IF functions, comparison operators, pivot tables, named ranges, and solving transportation problems using the Solver tool. Step-by-step explanations are given for setting up and using each of these Excel features to organize, analyze, and visualize data. The document covers many common tasks and analysis techniques in Microsoft Excel.

Uploaded by

Muhammad Aftab
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)
49 views55 pages

Lab 7

This document provides instructions for using various Excel functions and tools including creating tables, removing duplicate values, budgeting, date validation, drop-down lists, counting numeric or text values, using IF functions, comparison operators, pivot tables, named ranges, and solving transportation problems using the Solver tool. Step-by-step explanations are given for setting up and using each of these Excel features to organize, analyze, and visualize data. The document covers many common tasks and analysis techniques in Microsoft Excel.

Uploaded by

Muhammad Aftab
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/ 55

MS EXCEL LAB 7

Introduction to computing

DECEMBER 11, 2020


MR. MUBASHAR SAEED
Dr. Fiza Murtaza
Table of Contents
1. Create a Table ................................................................................................................................................................................ 3
2. Remove Duplicate Values .............................................................................................................................................................. 4
3. Budget............................................................................................................................................................................................ 4
4. Date Validation .............................................................................................................................................................................. 8
Reject Invalid Dates ............................................................................................................................................................................... 8
Outside a Date Range .................................................................................................................................................................. 8
5. Drop-down List .............................................................................................................................................................................. 9
Create a Drop-down List............................................................................................................................................................. 9
Add/Remove Items .................................................................................................................................................................... 11
7. Count if Numeric Criteria ............................................................................................................................................................. 13
8. Text Tricks .................................................................................................................................................................................... 15
9. Count Blank/Nonblank Cells ........................................................................................................................................................ 18
10. Simple If Examples ................................................................................................................................................................... 20
11. And/Or Criteria ........................................................................................................................................................................ 21
12. Comparison Operators ............................................................................................................................................................ 23
Equal to....................................................................................................................................................................................... 23
Greater than ............................................................................................................................................................................... 23
Less than ..................................................................................................................................................................................... 24
Greater than or equal to............................................................................................................................................................ 25
Less than or equal to ................................................................................................................................................................. 25
Not Equal to ............................................................................................................................................................................... 26
Or ......................................................................................................................................................................................................... 27
13. Dated if .................................................................................................................................................................................... 31
Today's Date .......................................................................................................................................................................................... 33
Today and Now .......................................................................................................................................................................... 33
Calculate Age ......................................................................................................................................................................................... 33
Separate Strings ..................................................................................................................................................................................... 35
Text to Columns .................................................................................................................................................................................... 36
Change Case .......................................................................................................................................................................................... 39
14. Pivot Tables.............................................................................................................................................................................. 41
Insert a Pivot Table ................................................................................................................................................................... 41
Drag fields .................................................................................................................................................................................. 42
Sort .............................................................................................................................................................................................. 43
Filter............................................................................................................................................................................................ 44
Change Summary Calculation.................................................................................................................................................. 44
15. Named Range .......................................................................................................................................................................... 46
16. Solver Transportation Problem ............................................................................................................................................... 48
Formulate the Model ................................................................................................................................................................. 48
Trial and Error .......................................................................................................................................................................... 49
Solve the Model .......................................................................................................................................................................... 50
1.Create a Table
If you already have an organized range of data, you can turn it into a table. Before turning a range of data into
a table, remove blank rows and columns, and make sure that a single column doesn’t have different types of
data within it.

1. Click a cell in the range you want to convert to a table.

2. Click the Format as Table button on the Home tab.


3. Select the table style you want to use.

You can also click the Insert tab on the Ribbon and click the Table button in the Tables group.
4. Verify the data range includes all the cells you want to include in the table.

Make sure to specify whether the table has a header row. If it doesn’t, Excel will add a header row above
the table data.

5. Click OK.

The table is created. Filters are added to each column and the table is automatically formatted. Under Table
Tools on the Ribbon, the Design tab appears.

You can change the appearance of a table at any time by applying a preset table formatting style.

1. Click a cell in the table.

2. Click the Design tab.


3. Click the Quick Styles button from the Table Style group.

The table styles gallery appears. Here you can select styles from the Light, Medium, or Dark categories.
You may need to scroll down the list to see the Dark category.

4. Select a style.
2.Remove Duplicate Values
1. Select a cell in the table.

2. Click the Data tab.


3. Click the Remove Duplicates button.
All columns are selected by default, but it’s possible to select/deselect individual columns in the
Columns list. You can also use the Select All and Unselect All buttons to select columns.
4. Select the columns you want to check for duplicates.

5. Click OK.

3.Budget
Enter the different type of income and expenses in column A.

Note: On the Home tab, in the Font group, you can use the different commands to change the font size and font style of
text. Click on the right border of the column A header to increase the column width.

Enter the word Jan into cell B2. Next, select cell B2, click the lower right corner of the cell and drag it across to cell M2.
Excel automatically adds the other months.
3. Enter some data.

4. Enter the SUM function into cell B6. To achieve this, select cell B6, type an equal sign (=), enter SUM(, select the
range B4:B5, close with a ")" and press Enter.
Note: On the Home tab, in the Font group, you can add a top border.

5. Select cell B6, click the lower right corner of the cell and drag it across to cell M6. Excel copies the function and
border to the other cells.
6. Enter the SUM function into cell O4. Remember, select cell O4, type =SUM(, select the range B4:M4, close with a
")" and press Enter.

7. Drag cell O4 down to cell O6.

8. Repeat steps 4 to 7 for the expenses.

9. Add a Short/Extra row.


4.Date Validation
Reject Invalid Dates

. Select the range A2:A4.

2. On the Data tab, in the Data Tools group, click Data Validation.

Outside a Date Range


3. In the Allow list, click Date.

4. In the Data list, click between.

5. Enter the Start date and End date shown below and click OK.
Explanation: all dates between 5/20/2016 and today's date + 5 days are allowed. All dates outside this date range are
rejected.

6. Enter the date 5/19/2016 into cell A2.

Result. Excel shows an error alert.

Note: to enter an input message and error alert message, go to the Input Message and Error Alert tab.

5.Drop-down List
Drop-down lists in Excel are helpful if you want to be sure that users select an item from a list, instead of typing their
own values.
Create a Drop-down List
To create a drop-down list in Excel, execute the following steps.

1. On the second sheet, type the items you want to appear in the drop-down list.

Note: if you don't want users to access the items on Sheet2, you can hide Sheet2. To achieve this, right click on the sheet
tab of Sheet2 and click on Hide.

2. On the first sheet, select cell B1.


3. On the Data tab, in the Data Tools group, click Data Validation.

The 'Data Validation' dialog box appears.

4. In the Allow box, click List.

5. Click in the Source box and select the range A1:A3 on Sheet2.

6. Click OK.

Result:
Note: to copy/paste a drop-down list, select the cell with the drop-down list and press CTRL + c, select another cell and
press CTRL + v.

7. You can also type the items directly into the Source box, instead of using a range reference.

Note: this makes your drop-down list case sensitive. For example, if a user types yes, an error alert will be displayed.
Add/Remove Items
You can add or remove items from a drop-down list in Excel without opening the 'Data Validation' dialog box and
changing the range reference. This saves time.

1. To add an item to a drop-down list, go to the items and select an item.

2. Right click, and then click Insert.

3. Select "Shift cells down" and click OK.


Note: Excel automatically changed the range reference from Sheet2!$A$1:$A$3 to Sheet2!$A$1:$A$4. You can check
this by opening the 'Data Validation' dialog box.

4. Type a new item.

Result:

6. To remove an item from a drop-down list, at step 2, click Delete, select "Shift cells up" and click OK.
7.Count if Numeric Criteria
Use the COUNTIF function in Excel to count cells that are equal to a value, count cells that are greater than or equal to
a value, etc.

1. The COUNTIF function below counts the number of cells that are equal to 20.

2. The following COUNTIF function gives the exact same result.

3. The COUNTIF function below counts the number of cells that are greater than or equal to 10.
4. The following COUNTIF function gives the exact same result.

Explanation: the & operator joins the 'greater than or equal to' symbol and the value in cell C1.

5. The COUNTIF function below counts the number of cells that are not equal to 7.

6. The COUNTIF functions below count the number of cells that are equal to 3 or 7.
8.Text Tricks
Use the COUNTIF function in Excel and a few tricks to count cells that contain specific text. Always enclose text in
double quotation marks.

1. The COUNTIF function below counts the number of cells that contain exactly star.

2. The COUNTIF function below counts the number of cells that contain exactly star + 1 character. A question mark (?)
matches exactly one character.
3. The COUNTIF function below counts the number of cells that contain exactly star + a series of zero or more
characters. An asterisk (*) matches a series of zero or more characters.

4. The COUNTIF function below counts the number of cells that contain star in any way.
5. The COUNTIF function below counts the number of cells that contain text.
9.Count Blank/Nonblank Cells

1. The COUNTBLANK function below counts the number of blank cells in the range A1:A7.

2. The COUNTA function below counts the number of nonblank cells in the range A1:A7. COUNTA stands for count
all.

3. The COUNTIFS function below counts the number of blank cells in the range B1:B7 with one additional criteria
(blue).
Explanation: the COUNTIFS function (with the letter S at the end) in Excel counts cells based on two or more criteria.
Use an empty string (two double quotes with nothing in between) to find blank cells.

4. The COUNTIFS function below counts the number of nonblank cells in the range B1:B7 with one additional criteria
(pink).
The IF function is one of the most used functions in Excel. This page contains many easy to follow IF examples.

10. Simple If Examples


The IF function checks whether a condition is met, and returns one value if true and another value if false.

Explanation: if the price is greater than 500, the IF function returns High, else it returns Low.

1b. The following IF function produces the exact same result.

Note: you can use the following Comparison Operator = (equal to), > (greater than), < (less than), >= (greater than or
equal to), <= (less than or equal to) and <> (not equal to).
2. Always enclose text in double quotation marks.

3a. The formula below calculates the progress between two points in time.
3b. You can use the IF function to display an empty string if the end value hasn't been entered yet (see row 5).

Explanation: if the end value is not empty (<> means not equal to), the IF function calculates the progress between the
start and end value, else it displays an empty string (two double quotes with nothing in between).

11. And/Or Criteria


Use the IF function in combination with the AND function and the OR and become an Excel expert.
1. For example, take a look at the IF function in cell D2 below.
Explanation: the AND function returns TRUE if the first score is greater than or equal to 60 and the second score is
greater than or equal to 90, else it returns FALSE. If TRUE, the IF function returns Pass, if FALSE, the IF function
returns Fail.

2. For example, take a look at the IF function in cell D2 below.

Explanation: the OR function returns TRUE if at least one score is greater than or equal to 60, else it returns FALSE. If
TRUE, the IF function returns Pass, if FALSE, the IF function returns Fail.

3. For example, take a look at the IF function in cell D2 below.

Explanation: the AND function above has two arguments separated by a comma (Table, Green or Blue). The AND
function returns TRUE if Product equals "Table" and Color equals "Green" or "Blue". If TRUE, the IF function reduces
the price by 50%, if FALSE, the IF function reduces the price by 10%.
12. Comparison Operators

Use comparison operators in Excel to check if two values are equal to each other, if one value is greater than another
value, if one value is less than another value, etc.
Equal to
The equal to operator (=) returns TRUE if two values are equal to each other.
1. For example, take a look at the formula in cell C1 below.

Explanation: the formula returns TRUE because the value in cell A1 is equal to the value in cell B1. Always start a
formula with an equal sign (=).

2. The IF function below uses the equal to operator.

Explanation: if the two values (numbers or text strings) are equal to each other, the IF function returns Yes, else it
returns No.
Greater than
The greater than operator (>) returns TRUE if the first value is greater than the second value.
1. For example, take a look at the formula in cell C1 below.
Explanation: the formula returns TRUE because the value in cell A1 is greater than the value in cell B1.

2. The OR function below uses the greater than operator.

Explanation: this OR function returns TRUE if at least one value is greater than 50, else it returns FALSE.
Less than
The less than operator (<) returns TRUE if the first value is less than the second value.
1. For example, take a look at the formula in cell C1 below.

Explanation: the formula returns TRUE because the value in cell A1 is less than the value in cell B1.

2. The AND function below uses the less than operator.


Explanation: this AND function returns TRUE if both values are less than 80, else it returns FALSE.
Greater than or equal to
The greater than or equal to operator (>=) returns TRUE if the first value is greater than or equal to the second value.
1. For example, take a look at the formula in cell C1 below.

Explanation: the formula returns TRUE because the value in cell A1 is greater than or equal to the value in cell B1.

2. The COUNTIF function below uses the greater than or equal to operator.

Explanation: this COUNTIF function counts the number of cells that are greater than or equal to 10.
Less than or equal to
The less than or equal to operator (<=) returns TRUE if the first value is less than or equal to the second value.
1. For example, take a look at the formula in cell C1 below.
Explanation: the formula returns TRUE because the value in cell A1 is less than or equal to the value in cell B1.

2. The SUMIF function below uses the less than or equal to operator.

Explanation: this SUMIF function sums values in the range A1:A5 that are less than or equal to 10.
Not Equal to
The not equal to operator (<>) returns TRUE if two values are not equal to each other.
1. For example, take a look at the formula in cell C1 below.

Explanation: the formula returns TRUE because the value in cell A1 is not equal to the value in cell B1.

2. The IF function below uses the not equal to operator.


Explanation: if the two values (numbers or text strings) are not equal to each other, the IF function returns No, else it
returns Yes.

Or

The OR function in Excel returns TRUE if any of the conditions are true and returns FALSE if all conditions are false.
Combine the OR function with other functions and become an Excel expert.
1. For example, take a look at the OR function in cell D2 below.

Explanation: the OR function returns TRUE if the first score is greater than 70 or the second score is equal to 100, else it
returns FALSE.

2. Combine the OR function with the IF function.


Explanation: the OR function returns TRUE or FALSE (see previous example). If TRUE, the IF function returns Pass, if
FALSE, the IF function returns Fail.

3. For example, take a look at the OR function in cell E2 below.

Explanation: the OR function returns TRUE if at least one score is greater than or equal to 90, else it returns FALSE.
The OR function can test up to 255 conditions. The only way for the OR function to return FALSE is if all the
conditions are FALSE (row 6).

4. The array formula below uses the OR function to return TRUE if any cell in the range A1:E6 is greater than or equal
to 90.
Explanation: finish an array formula by pressing CTRL + SHIFT + ENTER. Excel adds the curly braces {}. The value
in cell D4 is greater than or equal to 90. As a result, the array formula returns TRUE.

5. Combine the OR function with the AND function.

Explanation: the AND Function returns TRUE if all conditions are true and returns FALSE if any of the conditions are
false. The AND function above has two arguments separated by a comma (Table, Green or Blue). The AND function
returns TRUE if Product equals "Table" and Color equals "Green" or "Blue".

6. Combine the OR function with the WEEKDAY function.


Explanation: the WEEKDAY function in Excel returns a number from 1 (Sunday) to 7 (Saturday) representing the day
of the week of a date. As a result, the OR function returns TRUE if the date falls on a weekend.

7. Don't confuse the OR function with the XOR (Exclusive OR) function.

Explanation: the XOR function returns TRUE if an odd number of conditions are true, and FALSE otherwise. With two
conditions (see example above) the XOR function returns TRUE if one condition is true (row 2) and returns FALSE if
both conditions are false (row 3, 4 and 6) or both conditions are true! (row 5).
13. Dated if

To get the number of days, weeks or years between two dates in Excel, use the DATEDIF function. The DATEDIF
function has three arguments.
1. Fill in "d" for the third argument to get the number of days between two dates.

Note: =A2-A1 produces the exact same result!

2. Fill in "m" for the third argument to get the number of months between two dates.

3. Fill in "y" for the third argument to get the number of years between two dates.

4. Fill in "yd" for the third argument to ignore years and get the number of days between two dates.
5. Fill in "md" for the third argument to ignore months and get the number of days between two dates.

6. Fill in "ym" for the third argument to ignore years and get the number of months between two dates.

Important note: the DATEDIF function returns the number of complete days, months or years. This may give
unexpected results when the day/month number of the second date is lower than the day/month number of the first date.
See the example below.
The difference is 6 years. Almost 7 years! Use the following formula to return 7 years.

Today's Date

To enter today's date in Excel, use the TODAY function. To enter the current date and time, use the NOW function. To
enter the current date and time as a static value, use keyboard shortcuts.
Today and Now
1. To enter today's date in Excel, use the TODAY function.

Calculate Age

To calculate the age of a person in Excel, use DATEDIF and TODAY. The DATEDIF function has three arguments.
1. Enter the date of birth into cell A2.

2. Enter the TODAY function into cell B2 to return today's date.


3. The DATEDIF function below calculates the age of a person.

Note: fill in "y" for the third argument to get the number of complete years between the date of birth and today's date.

4. Calculate the age of a person without displaying today's date.

5. Calculate the age of a person on a specific date.

Note: the DATE function accepts three arguments: year, month and day.

6. Calculate the age of a person in years, months and days.


Note: fill in "ym" for the third argument to ignore years and get the number of months between two dates. Fill in "md"
for the third argument to ignore months and get the number of days between two dates. Use the & operator to join
strings.
Separate Strings

This example teaches you how to separate strings in Excel.

The problem we are dealing with is that we need to tell Excel where we want to separate the string. In case of Smith,
Mike the comma is at position 6 while in case of Williams, Janet the comma is at position 9.

1. To get the first name, use the formula below.


Explanation: to find the position of the comma, use the FIND function (position 6). To get the length of a string, use the
LEN function (11 characters). =RIGHT(A2,LEN(A2)-FIND(",",A2)-1) reduces to =RIGHT(A2,11-6-1). =RIGHT(A2,4)
extracts the 4 rightmost characters and gives the desired result (Mike).

2. To get the last name, use the following formula.

Explanation: to find the position of the comma, use the FIND function (position 6). =LEFT(A2,FIND(",", A2)-1)
reduces to =LEFT(A2,6-1). =LEFT(A2,5) extracts the 5 leftmost characters and gives the desired result (Smith).

3. Select the range B2:C2 and drag it down.

Text to Columns

To separate the contents of one Excel cell into separate columns, you can use the 'Convert Text to Columns Wizard'. For
example, when you want to separate a list of full names into last and first names.
1. Select the range with full names.
2. On the Data tab, in the Data Tools group, click Text to Columns.

The following dialog box appears.

3. Choose Delimited and click Next.

4. Clear all the check boxes under Delimiters except for the Comma and Space check box.
5. Click Finish.

Note: This example has commas and spaces as delimiters. You may have other delimiters in your data. Experiment by
checking and unchecking the different check boxes. You get a live preview of how your data will be separated.

Result:
Change Case

To change the case of text in Excel, use LOWER, UPPER or PROPER. If you're not a formula hero, use Flash Fill
to change case in Excel.
1. Use the LOWER function in Excel to change the case of text to lowercase.

Note: double click the lower right corner of cell B1 to quickly copy this formula to the other cells.

2. Use the UPPER function in Excel to change the case of text to uppercase.

3. Use the PROPER function in Excel to change the first letter of each word to uppercase and all other letters to
lowercase.
If you're not a formula hero, use Flash Fill to change the case of text in Excel. In the example below, we are looking for
a mix of proper case and uppercase.

4. First, tell Excel what you want to do by entering the correct city (proper case) and state abbreviation (uppercase) into
cell B1.

5. On the Data tab, in the Data Tools group, click Flash Fill (or press CTRL + E).

Result:

Note: Flash Fill is not perfect and sometimes needs a little help. Visit our page about Flash Fill to learn more about this
great Excel tool.
14. Pivot Tables
Pivot tables are one of Excel's most powerful features. A pivot table allows you to extract the significance from a large,
detailed data set.
Our data set consists of 213 records and 6 fields. Order ID, Product, Category, Amount, Date and Country.

Insert a Pivot Table


To insert a pivot table, execute the following steps.
1. Click any single cell inside the data set.

2. On the Insert tab, in the Tables group, click PivotTable.

The following dialog box appears. Excel automatically selects the data for you. The default location for a new pivot
table is New Worksheet.

3. Click OK.
Drag fields
The PivotTable Fields pane appears. To get the total amount exported of each product, drag the following fields to the
different areas.
1. Product field to the Rows area.

2. Amount field to the Values area.

3. Country field to the Filters area.


Below you can find the pivot table. Bananas are our main export product. That's how easy pivot tables can be!

Sort
To get Banana at the top of the list, sort the pivot table.

1. Click any cell inside the Sum of Amount column.

2. Right click and click on Sort, Sort Largest to Smallest.


Result.

Filter
Because we added the Country field to the Filters area, we can filter this pivot table by Country. For example, which
products do we export the most to France?

1. Click the filter drop-down and select France.

Result. Apples are our main export product to France.

Note: you can use the standard filter (triangle next to Row Labels) to only show the amounts of specific products.
Change Summary Calculation
By default, Excel summarizes your data by either summing or counting the items. To change the type of calculation that
you want to use, execute the following steps.
1. Click any cell inside the Sum of Amount column.

2. Right click and click on Value Field Settings.

3. Choose the type of calculation you want to use. For example, click Count.

4. Click OK.

Result. 16 out of the 28 orders to France were 'Apple' orders.


15. Named Range

Create a named range or a named constant and use these names in your Excel formulas. This way you can make your
formulas easier to understand.
To create a named range, execute the following steps.

1. Select the range A1:A4.

2. On the Formulas tab, in the Defined Names group, click Define Name.

3. Enter a name and click OK.


There's an even quicker way of doing this.

4. Select the range, type the name in the Name box and press Enter.

5. Now you can use this named range in your formulas. For example, sum Prices.

To create a named constant, execute the following steps.


16. Solver Transportation Problem
Use the solver in Excel to find the number of units to ship from each factory to each customer that minimizes the total
cost.
Formulate the Model
The model we are going to solve looks as follows in Excel.

1. To formulate this transportation problem, answer the following three questions.


a. What are the decisions to be made? For this problem, we need Excel to find out how many units to ship from each
factory to each customer.

b. What are the constraints on these decisions? Each factory has a fixed supply and each customer has a fixed demand.

c. What is the overall measure of performance for these decisions? The overall measure of performance is the total cost
of the shipments, so the objective is to minimize this quantity.

2. To make the model easier to understand, create the following named ranges.
Range Name Cells

UnitCost C4:E6

Shipments C10:E12
TotalIn C14:E14

Demand C16:E16

TotalOut G10:G12

Supply I10:I12

TotalCost I16

3. Insert the following functions.

Explanation: The SUM functions calculate the total shipped from each factory (Total Out) to each customer (Total In).
Total Cost equals the sumproduct of UnitCost and Shipments.
Trial and Error
With this formulation, it becomes easy to analyze any trial solution.

For example, if we ship 100 units from Factory 1 to Customer 1, 200 units from Factory 2 to Customer 2, 100 units from
Factory 3 to Customer 1 and 200 units from Factory 3 to Customer 3, Total Out equals Supply and Total In equals
Demand. This solution has a total cost of 27800.
It is not necessary to use trial and error. We shall describe next how the Excel Solver can be used to quickly find the
optimal solution.
Solve the Model
To find the optimal solution, execute the following steps.

1. On the Data tab, in the Analyze group, click Solver.

Note: can't find the Solver button? Click here to load the Solver add-in.
Enter the solver parameters (read on). The result should be consistent with the picture below.
You have the choice of typing the range names or clicking on the cells in the spreadsheet.

2. Enter TotalCost for the Objective.

3. Click Min.

4. Enter Shipments for the Changing Variable Cells.

5. Click Add to enter the following constraint.


6. Click Add to enter the following constraint.

7. Check 'Make Unconstrained Variables Non-Negative' and select 'Simplex LP'.

8. Finally, click Solve.

Result:
The optimal solution:

Conclusion: it is optimal to ship 100 units from Factory 1 to Customer 2, 100 units from Factory 2 to Customer 2, 100
units from Factory 2 to Customer 3, 200 units from Factory 3 to Customer 1 and 100 units from Factory 3 to Customer
3. This solution gives the minimum cost of 26000. All constraints are satisfied.

You might also like