Advanced Excel users who are comfortable with creating and editing macros will find creating custom functions a snap. Even those who aren’t that familiar with VBA code can follow the steps below and create useful shortcuts to their calculations. This article will show how to create a very simple custom function (area of a triangle) to demonstrate the steps. You will have to figure out the math on your own!

**Prepare Your Workbook**

Because custom functions use VBA, your file must be saved as a .xlsm Macro-enabled workbook.

Follow the steps below in a new, clean macro-enabled workbook of your own, or download ** 06-Custom Functions.xlsm **to see the completed user defined function.

**Determine Your Variables**

A function creates a calculation based on variables input at the time the function is used. To create your custom function, you will first need to identify the arguments needed in your function. We are going to create a function to quickly calculate the area of a triangle: Area = Base times Height divided by 2, or A=BH/2. Our arguments will be the base and the height.

**Open Visual Basic Editor**

Hit **Alt + F11** or click the Visual Basic button the Developer tab.

Choose **Insert > Module** in the VBA editor:

**Type Code**

You will need to be familiar with VBA code to complete this step in your own work. The basic syntax of User Defined Function is:

**Function** myfunctionname (arguments) return type

Myfunctionname = calculation

**End Function**

Adding “Public” to Function tells Excel to list your User Defined Function in the **Insert Function** dialog box.

Here is simple sample code for our Triangle Area Function. When you are finished writing the code, save the function and close the editor.

**Public Function TRIAREA(number1, number2)
TRIAREA = (number1 * number2) / 2
End Function**

**Use Your User Defined Function**

Back in your Excel workbook, place your cursor in the place where you wish to insert the custom function:

- Click
**Insert Function**on the**Formulas tab**. - In the
**Insert Function**dialog box, select**User Defined**from the “select a category” dropdown list. You should see the name you gave your function. In this example we see TRIAREA. - Select the function, then click
**OK.** - Fill out the
**Function Arguments**dialog box and click**OK.**

Now you can use the TRIAREA function anytime you need to calculate the area of a triangle in your workbook. Note that you will only be able to use it in the workbook in which it was saved, it is not a global function.

**Hint!** If your variables are very specific – such as in our example, number1 will always be the Base of our triangle, and number2 will always be the Height – you can give them specific names to help you when you are completing the function in your workbook:

Conditional formatting is a useful Excel feature that can help you quickly scan your data without resorting to complicated filtering or fussy charts. Often, you will use conditional formatting to call attention to cells that represent an outlying condition – such as too many days until delivery or too few items in inventory.

Here’s how to use conditional formatting to show us that an item in our store is getting low on inventory and we will need to re-order soon:

- Highlight the cell in the row that indicates inventory, our “Units in Stock” column.
- Click
**Conditional Formatting**. - Select
**Highlight Cells Rules**, then choose the rule that applies to your needs. In this example, select**Less Than**. - Fill out the
**Less Than**dialog box and choose a formatting style from the dropdown. In Our example, we want the cell to change to red background and red text when the cell value is less than 20.

*To follow using our example, download 03-Conditional Formatting Across Multiple Cells.xls *

I’m sure you have already spotted a problem! There are many rows in our worksheet. Do I have to repeat the above for every cell in the column? Of course, the answer is “no” and Excel gives you a few quick ways to apply conditional formatting to multiple cells.

**Select Your Range Before You Begin**

By far the easiest way to apply conditional formatting to an entire column or row of cells, is to select the entire range to which the formatting will apply, *before *you define your rule. To highlight every cell with a value below twenty in our example, your steps would look like this:

- Highlight all of the cells in the sheet to which you’ll apply the formatting rules. Do NOT select headings.
- Click
**Conditional Formatting**. - Select
**Highlight Cells Rules**, then choose the rule that applies to your needs. In this example, select**Less Than**. - Fill out the
**Less Than**dialog box and choose a formatting style from the dropdown.

**Edit the Rule**

If you forget to select your range, or your range changes after you’ve applied the rule, you can modify it after the rule has been created:

- Place the cursor in any cell to which the conditional formatting rule applies.
- Click
**Conditional Formatting**, then select**Manage Rules**. - Click on the rule you wish to change. (If you don’t see your rule, you may not have selected a cell to which the rule applies. Click the
**Show formatting rules for:**dropdown and select**This Worksheet**to see all rules.) - Click inside the
**Applies to**field. - Type the new range of cells, or click the sheet button to click & drag your cursor around the new range of cells. When the
**Applies to**field reflects the correct new range, click**OK.**

**Click & Drag, Copy/Paste**

Once a conditional formatting rule has been applied to a cell, the rule will also apply to any cell that is copied from the original. This means you can copy/paste the rule (along with its contents!) and even use the copy handle to drag and copy the rule. **Caution!** Just like any other formula, you will need to pay attention to your absolute and relative cell values so that your conditional formatting rules are applied correctly.

**To delete your rule from multiple cells:**

- Open the
**Rules Manager**, select the rule and hit**Delete Rule**

**To delete all rules from your sheet:**

- Click
**Conditional Formatting > Clear Rules**and select**Clear Rules from Entire Sheet**

For more information about how to apply conditional formatting based on formulas, and how to highlight entire rows of data, view this article: **Get the Most Out of Excel’s Conditional Formatting**

If you are a fan of Excel’s conditional formatting feature, you probably find looking for even more and more ways to highlight useful information in your data. A question that often comes up among these “conditional formatting addicts” is **Can I use If/Then formula to format a cell?**

The answer is yes and no. Any conditional formatting argument must generate a TRUE result, meaning that at a literal level, your conditional formatting rule *is* an If/Then statement along the lines of “If this condition is TRUE, THEN format the cell this way”.

What conditional formatting can’t do in a *single* rule is an IF/THEN/ELSE condition such as “If # is greater than 10 format red, else format green”. Instead, this would require TWO rules, one for “greater than 10” and one for “less than 10”.

Let’s look at a few scenarios to get a sense of how we can create the effect of IF/THEN conditional formatting, even if we can’t use it in the feature itself:

*To follow using our examples, download 04-If-Then Conditional Formatting.xlsx*

**Scenario 1 (Birthdays tab)**: You want to highlight all employees in your department who have a birthday this month with Red, and all other departments blue.

**Solution: **Create two rules – one for your department, one for all others

**Step 1 – Highlight birthdays in your department**

The formula to identify birthdays in the current month will be (see this article for more about using dates in conditional formatting):

To create a formula that generates a TRUE/FALSE statement that highlights birthdays only in one department, you would use the formula:

*This example was created in April, so April birthdays will be highlighted. If you are reproducing the exercise in a different month, you will see different results! *

Then, create a second rule for the same range using this formula to highlight birthdays that are not in your department:

**BONUS!** In this example, we applied the rule to the department cell to show the relationship to the formula. By changing the **Applies to** range, however, you can easily highlight a different cell – such as the birthdate – or the entire row. See **Get the Most Out of Excel’s Conditional Formatting** for more ideas.

**Scenario 2 (Retainers tab): **You have a table of how many hours your employees have worked for specific clients, and you have a table of how many hours each client has in their retainer budget. You want to highlight the clients who are over their retainer.

**Solution 1**: Create a helper column using IF/THEN formula to call out whether a client is over their retainer budget. If your worksheet already has the IF/THEN/ELSE logic you need embedded in a cell, Conditional Formatting can act based on those results. You don’t necessarily need to reproduce the logic in the rule itself.

In this example, we already have an IF/THEN formula that returns the result “YES” if our client is over their retainer budget. Our Conditional Formatting rule, then only has to look for the text string “YES” and apply the formatting when true.

Highlight the cell range, Click on **Conditional Formatting > Highlight Cell Rules > Text that Contains** to create the Rule, then type YES in the **Text that Contains** dialog box.

**Solution 2**: Create a formula to calculate retainer budget.

If you don’t have, or don’t want to create, a helper column with an IF/THEN statement, you can use the same method as the first scenario by creating a rule that determines whether a client is over budget. In this example, we applied the rule to the **Client **cells and the formula would be:

If you are used to creating complex formulas that cover all cases in one cell, it may take a little re-learning to figure out the approach for conditional formatting that works more incrementally. The best hint is to remember that you can apply multiple rules to the same cells – break up your formatting criteria into separate steps, and you’ll most likely be able to get where you need to be!

]]>**What is nesting?**

Nesting refers to using a function as one of the arguments inside another function.

**When do you use nesting?**

Nesting functions is useful when you need to make several calculations to get to your desired answer, but don’t need to see the results of those steps as you go.

**How do I keep my nested functions straight?**

If you’ve ever looked at someone else’s worksheet and felt your eyes glaze over at the long strings of numbers, cell references and function names, you’re not alone. It takes practice to “read” complex formulas. Here are a couple of quick tips:

**Know your function’s arguments –**Knowing that the IF function has 3 arguments separated by commas (criteria, if true return, otherwise return) will help you sort out what each nested function is meant to accomplish.**Count your parenthesis**– Just like in math equations and computer programs, parenthesis keep instructions organized and tell you what order the calculations are performed. When creating nested functions, you will need to make sure that all of your open parenthesis have closing parenthesis and that they’re in the right place!**Don’t work left to right, work inside out!**– It’s tempting to try to build a complex nested formula by starting at the beginning of the line.*Instead*write the internal functions first, then place them*as a unit*into the arguments of the outer functions.

Let’s do an example. *To follow along, download 05-Nested Function Tutorial.xlsx*

Our worksheet shows six food items – 3 healthy and 3 sweet – and how many students chose each for their afternoon snack over 5 days.

We want to know how many more students, on average, chose sweet snacks instead of healthy snacks.

To make that calculation we will need the following information. To answer the question without nested functions, you could use multiple additional cells and the formulas in the example below:

- Average of each snack: =AVERAGE(B2:B6), =AVERAGE(C2:C6), =AVERAGE(D2:D6), and so on
- Average of each
*kind*of snack: =SUM(E7:G7) & =SUM(B7:D7) - Difference between healthy average and sweet average: =C9-C10

*See Multiple Cells Tab*

As you can see, each calculation is contained in its own cell, and the final “Difference” formula is built on the results of those cells. If, however, we don’t care about the average per snack or snack type, and ONLY want to see the “Difference”, we can nest our functions into one long formula.

Let’s do it first in plain language. To calculate the difference, we’ll need to subtract the total average of healthy snacks from the total average of sweet snacks:

**Difference = (average number of sweet snacks) minus (average number of healthy snacks)**

The average number of sweet snacks is calculated by adding together the average number of each individual snack in the category. Our formula will be:

**Average number of healthy snacks = (Average of Apples + Average of Bananas + Average of Carrots)****Average number of sweet snacks = (Average of Donuts + Average of Cookies + Average of Gummy Bears)**

Working inside-out, now fill each snack category parenthesis with the correct function:

**Average number of healthy snacks = SUM(AVERAGE(B2:B6), AVERAGE(C2:C6), AVERAGE(D2:D6))****Average number of sweet snacks = SUM(AVERAGE(E2:E6), AVERAGE(F2:F6), AVERAGE(G2:G6))**

Notice that the parenthesis around the SUM arguments stack up at the end. You need both end parenthesis to “close” the AVERAGE function and the SUM function.

Now, using these complete functions, we can now put them in the difference equation, for a final result of:

**=SUM(AVERAGE(E2:E6), AVERAGE(F2:F6), AVERAGE(G2:G6))– SUM(AVERAGE(B2:B6), AVERAGE(C2:C6), AVERAGE(D2:D6))**

When you plug in the above, you get the same result as the first formula, but you don’t need to have any of the additional helper cells!

*See Nested Functions Tab*

This example is probably a bit much for a simple problem, but it should illustrate the benefits and techniques of nesting functions to create more complex formulas without adding additional clutter to your sheets.

What are your tricks for working with nested functions without getting “lost in the parenthesis”?

]]>**Highlight Upcoming Birthdays**

If you are in charge of sending a birthday message to every employee each month, you can use conditional formatting to quickly highlight who has a birthday in the current month without sorting or filtering.

**How to Do It:**

- Select the range of cells that contains the birthday data. Do not include headings.
- On the
**Home**tab, click**Conditional Formatting**. - Select
**New Rule.** - Select
**Use a formula to determine which cells to format.** **Use Excel’s MONTH function to find the cells that contain birthdates in the current month. Use the TODAY function as your comparison date so the spreadsheet will always be current when you open it. (The example was written on April 20.) Your formula would be:**

- Click the
**Format**button to specify how you want the matching cell to appear. - Click
**OK**.

*To follow using our example, download FPS_Conditional Formatting Date Data.xls*

More Ideas:

- Calculate birthdays occurring in the current week:
**=WEEKNUM(C2)=WEEKNUM(TODAY())**(

**WARNING!**Note that dates can fall on different weeks in different years just as your birthday won’t be on the same day of the week each year. This method will work for highlighting upcoming birthdays on a regular basis, but may not be appropriate for other uses.) - Color code by department:
- Use the AND function to specify multiple criteria for the condition. Specify the Department in the formula, and the formatting you want in the dialog box:
**=AND(MONTH(C2)=MONTH(TODAY()),D2=”Sales”)** - Then, follow the steps above to create separate Rules for the other departments. Your results might look something like this image:

- Use the AND function to specify multiple criteria for the condition. Specify the Department in the formula, and the formatting you want in the dialog box:

**Highlight Specific Anniversaries Each Month**

If you want to highlight specific upcoming birthdays – such as a 65^{th} birthday – or anniversaries, that will take a little more formula work.

- Our first condition will find birthdays happening this month as we did above with the formula:
**=MONTH(C2)=MONTH(TODAY())** - Then we’ll use the YEAR function to find birth years that are 65 years ago:
**=YEAR(TODAY())-YEAR(C2)** - The AND function combines the two for our conditional formatting result of:
**=AND(YEAR(TODAY())-YEAR(C2)=65,MONTH(C2)=MONTH(TODAY()))**

Each time you open the workbook, you wil find the current month’s 65^{th} birthdays highlighted.

Hint! To make your birthday calculations even more visually appealing, highlight the entire row instead of just the date cell.

]]>Do you speak Excel? Are you just starting out and trying to remember the go-to lingo? Well, today’s blog post is a snapshot of helpful cheat sheet material to help you build your Excel skills.

As you continue working in Excel, you’ll learn additional uses as you build formulas to meet your specific needs. The great thing about Excel is that it is flexible enough to allow just about any calculation you might need – and now you have a reference tool to decipher it!

]]>*To follow using our example, download FPS_Apply Conditional Formatting.xlsx*

**Use Icons Instead of Formatting**

When you want a little more visual interest than colored text and backgrounds, you can use conditional formatting to display icon sets.

How to do it:

- Select the column or data range.
- Open the
**New Formatting Rule**dialog box by clicking the**Conditional Formatting**dropdown button and selecting**New Rule**. (You can use the**Icon Sets**option in the dropdown menu if default settings are acceptable.) - In the
**Format Style**dropdown menu, select**Icon Sets**. - Choose the type of icons you want in the
**Icon Style**dropdown. - In the lower half of the dialog, you can set specific criteria for how each icon is displayed. In this example, we want:
- Donors who gave 5000 and up to show a full yellow star
- Donors who gave 500-5000 to show a half yellow star
- Donors who gave 500 and less to show an empty star

You can display icons based on percentages and custom formulas by changing the **Value **and **Type** criteria.

**Highlight an entire row or column**

When you are looking at data that has many columns, highlighting just one cell might not be enough for you to see the whole picture. Instead, highlight the whole row!

How to do it:

- Select the entire data range (excluding column headings).
- Open the
**New Formatting Rule**dialog box by clicking the**Conditional Formatting**dropdown button and selecting**New Rule**. - Select
**Use a formula to determine which cells to format**. - Enter the formula that describes your conditions. In this example, we want to highlight all rows of customers from Illinois so our formula will be:
**=$D2=”Illinois”****D2**is the first cell in our data that has the text we are looking for. Because the conditional logic works like copy/paste in Excel as it is applied to each cell in the range, you need to put the**$**symbol in front of the column letter to make it absolute. Do*not*put it in front of the row number as you want the formula to evaluate each new row. - Hit
**OK**to close the dialog box and apply the formatting.

Click **Manage Rules** to view and edit the conditional formatting formulas if needed. Notice that the **Applies to** field includes the range that we selected at the beginning.

**Calculate and Highlight Date Data**

A frequent task for any business that manages personal information is to calculate ages from birthdates. Using the technique above to highlight an entire row, we can use the following formula in the **Format values where the formula is true **field to help us see which members on the list are 65 or older:

**=INT(YEARFRAC($G2,TODAY()))>65**

Learn more about date functions here.

There’s much more that conditional formatting can do for your data than highlight red text. These ideas should get you started and give you some new areas of Excel to explore!

]]>Excel has several built in conditions you should explore.

To apply conditional formatting to a cell or range:

- Select the cells you want to format.
- Go to the
**Home**tab. - Click the
**Conditional Formatting**dropdown button. - Select the type of formatting you want.
- Select the sub-type of formatting you want.

- Enter any value and formatting specifications, if needed.
- Click
**OK**(if you are in a dialog box).

To edit conditional formatting:

- Go to the
**Home**tab. - Click the
**Conditional Formatting**dropdown button. Click on**Manage Rules**– this will open up the**Rules Manager**dialog box. - Here you can
**Edit Rule**, create**New Rule**, and**Delete Rule**. - Once you are finished click
**OK**.

To remove conditional formatting:

- Go to the
**Home**tab. - Click the
**Conditional Formatting**dropdown button. - Click on
**Clear Rules**. - Choose to clear rules from the selected cells or from the entire sheet.

With this tool at your disposal, you can quickly determine the top 10% paid based on salary, compare the highest and lowest data figures at a glance, and so much more. Play around with a workbook you frequently use to discover countless applications for conditional formatting!

]]>*To follow using our example, download ExportWorksheetsToWord.xlsx. You will need a blank Word document open. *This feature applies to Excel/Word 2010 and later versions. Images were taken using Excel 2013 on Windows 7.

**Solution One: Copy/Paste**

The simplest way to display Excel data in a Word document is to use Copy/Paste.

- Open the destination Word document.
- In the source Excel spreadsheet, select the data you want to copy then hit CTRL-C.
- In the destination Word document, place the cursor where you want the data, then hit CTRL-V.

- The default paste will use the
**Keep Source Formatting (A)**paste option. This preserves any formatting you have done in Excel and pastes the data into Word as a table using that same formatting. As you can see, you may need to clean up your table after the paste to make it look correct in the new document. - To change the paste option, click the
**Ctrl**dropdown option in the bottom right corner of your new table after pasting and select a new option. Other Paste options include:

**Use Destination Styles (B)**– This will paste the data into Word as a table and adapt the display elements into the same formatting as the Word document. Use this to make your fonts and colors consistent in the destination without having to edit in Excel beforehand.**Copy as Picture****(C) –**This will paste the data range as a Word image object. You will be able to resize and edit the image as you would any other picture, but you will not be able to edit the data. The paste will use the original Excel formatting to generate the picture.**Keep Text Only (D)**– This will paste the data contained within each cell as individual lines of text in the Word document. Data in columns will be separated by a tab, rows will appear as individual paragraphs.

**Hint!** If you frequently use a paste option that is not **Keep Source Formatting**, you can click the **Set Default Paste** link and change the default settings in the **Cut, copy and paste** section of **Word Options**.

** **

**Solution Two: Insert Excel Object**

Copy/Paste brings Excel tables or Worksheet *data* into the Word document by changing it to a Word table or text. Inserting your workbook as an Excel object embeds a mini-version of Excel itself into the middle of your Word document. This Excel object can include multiple sheets, filters and many of Excel’s features.

- Click the
**Insert**tab the destination Word document, then select**Object**from the**Insert Embedded****Object**dropdown button.

- Select the
**Create from File**tab, then browse to the workbook you wish to embed. - Choose whether you wish the object to be linked or not:
- A linked object will automatically update in the destination Word document if the source Excel spreadsheet is changed.
- An object that is not linked will not be updated automatically in the Word document if the source is changed.

- Click
**OK**to complete the embed.

If your object is not linked, you can edit the data directly – including formulas – from within Word. Double-click on the table and make changes as you would in Excel. If the object is linked, then clicking on the table will open the Excel window.

**Solution Three: Insert a Blank Excel Table**

If you will be creating or entering your data table from scratch within Word, but want the functionality of an Excel spreadsheet, you can embed a blank Excel spreadsheet and work just as you would in Excel.

- Click the
**Insert**tab, then select**Excel Spreadsheet**from the**Table**dropdown menu. - Double-click on the worksheet. The Excel ribbon will appear and you will be able to add your data, insert formulas and filter and display the data as if you were working directly in Excel.
- Click outside the spreadsheet pane or hit Escape to continue editing your Word document.

]]>

**Set up Your Data**

Designing your tables, headings and planning your workbooks before you begin entering or downloading data will save you time and headaches in the long run. Here are several things to think about before committing your data to Excel:

- Plan your headings. Don’t split up your data just to categorize it. Instead, create a column for the category and let your charts and PivotTables organize it in reports.

- Formulas should never contain numbers. Instead, assign a cell to each variable in the formula and then reference the
*cell*. This will make it much easier to find and make changes to those variables in the future. - Resist the urge to format your spreadsheets with extra headings subtotals or empty rows and columns to make the sheets visually pleasing. Keep your data tight and efficient. Then, use charts, graphs and PivotTables to share your analyses.
- Get in the habit of using fixed cell references for your formulas. This allows you to more easily copy/paste and re-use formulas throughout the workbook and also reduces errors.
- Lock cells with formulas so they are protected from mis-typing or deleting. In a very large spreadsheet, finding a single accidental keystroke can be harder than the proverbial needle in a haystack. To lock individual cells (without protecting an entire sheet, etc.):
- In an unprotected worksheet, type CTRL-A to select the entire worksheet.
- Click the dialog box launcher in the
**Font**group on the**Home**tab. - Click the
**Protection**tab in the**Format Cells**dialog box. - Un-check
**Locked**and click**OK****.** - Then, select ONLY the cells you want to protect (those with formulas). Repeat Steps 2-3.
- Re-check
**Locked**only for those cells and click**OK**. - On the
**Review**tab, click**Protect Sheet.**

**Enter Your Data**

Once you have designed your tables and workbooks, you will want to make sure that the data itself is consistent and accurate:

- Use data validation. This will help ensure that the data formats are correct (09 vs. 2009 for example) and catch common mistakes such as numbers out of range. The Excel data validation feature also lets you prompt the user for the correct data and warns them when they have entered incorrectly.

- Use forms. Especially if your records are to be entered by typing at the keyboard, as opposed to an import from other sources, a form can create a user-friendly interface that facilitates faster entry and also protects the existing data from accidental overwriting.
- If you are using imported data, resist the temptation to spend time editing it into your style and formats. This is likely to introduce errors and wastes time. Instead, proceed with your analysis and reporting in
*other sheets*where you can design the look as you create the report.

**Maintain Your Data**

As you add and delete records over time, you will inevitably reach a point where old records need to be purged, duplicates need to be reconciled and data needs to be re-formatted. The feature you’ll need depends upon your problem, but here is a list of articles that can help with some of the most common.

How to Find & Eliminate (or Use!) Duplicates in Excel Data

Remove Extra Spaces from Excel Data

Learn about the Excel Find Formula

Most importantly, before you begin ANY maintenance on an Excel database, you must back it up! Make a copy or two and save the originals in a safe place. Then, if anything goes wrong, you can recover and start over.

]]>