Lab 7
Lab 7
Introduction to computing
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.
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.
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.
2. On the Data tab, in the Data Tools group, click Data Validation.
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.
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.
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.
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.
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.
Explanation: if the price is greater than 500, the IF function returns High, else it returns Low.
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).
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.
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 (=).
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.
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.
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.
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.
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.
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".
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.
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.
Note: fill in "y" for the third argument to get the number of complete years between the date of birth and today's date.
Note: the DATE function accepts three arguments: year, month and day.
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.
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).
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.
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.
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.
Sort
To get Banana at the top of the list, sort the pivot table.
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?
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.
3. Choose the type of calculation you want to use. For example, click Count.
4. Click OK.
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.
2. On the Formulas tab, in the Defined Names group, click Define Name.
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.
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
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.
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.
3. Click Min.
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.