The formula used in this tutorial will work for any text character, and can also be used to count the occurrences of specific words in a cell.

In this example, we used the formula to count the occurrences of the asterisk in the cells of column A.

The formula below was used to return the number of times the asterisk appears. It uses the LEN and SUBSTITUTE functions to accomplish its mission.

=LEN(A2)-LEN(SUBSTITUTE(A2,"*",""))

The LEN function is used to count the total number of characters in a cell.

The second half of the formula uses the LEN function again but with the SUBSTITUTE function. SUBSTITUTE replaces all occurrences of the asterisk with nothing, essentially removing them.

So what we are left with is a formula that subtracts the number of characters in the cell excluding the asterisks from the total number of characters including asterisks.

The result is how many asterisks there are in the cell.

It is a clever approach that can be applied for any word, phrase or text character.

To do this we will first need to insert checkboxes onto the spreadsheet, we then need to be able to highlight an item when it is completed.

In this tutorial I am using the idea of a Christmas shopping list of names (shown below). Your checklist could however be for any list of tasks, inventory or products.

To insert checkboxes in Excel, you need the Developer tab on the Ribbon. If you do not have this, right mouse click on the Ribbon, select **Customize the Ribbon** and then check the **Developer** box.

On the **Developer** tab, click the **Insert** button of the Controls group and then click the **Check Box (Form Control)** button.

Click and drag to draw the checkbox onto the spreadsheet. Resize and position the checkbox so that is neatly fits inside a single cell. Right mouse click the checkbox and select **Edit Text** to change the default label. In this tutorial I have deleted the text next to the checkbox.

Select the cell containing the checkbox (not the checkbox itself) and copy and paste that cell to all the others in the list where you will need a checkbox.

You then need to link the checkbox value to a cell. Select the checkbox by pressing **Ctrl** and clicking on it. Then type = in the Formula Bar and select the cell you want to link the checkbox value to.

In this example I have used cell A4. The font of column A has been set as white so the values are not visible to the user. When linking to a cell only absolute cell references can be used such as =$A$4. Unfortunately this means you need to repeat this process for every checkbox in the list.

When a box is checked this linked cell displays TRUE, and if not will display FALSE (or blank if unused). So column A will be used to know if a box is checked or not.

With the checkboxes in place we want to automatically format the items when they are checked by writing a Conditional Formatting rule.

We will need a basic formula for this because the Conditional Formatting rule will refer to a cell outside the selected range.

- Select the range of cells that you want to apply the formatting to. In this example I selected the entire table, range B4:C8 in the image above.
- Click the
**Home**tab,**Conditional Formatting**and**New Rule**. - Select
**Use a formula to determine which cells to format**, and enter*=$A4=TRUE*. In this example, cell A4 is the first cell in the table that contains the response from a checkbox click. - Click the
**Format**button and choose what formatting you want to apply.

With the data in column A tracking the items to checked, you could take the checklist further and create totals for how many items checked, or how many unchecked. You could even then show this information graphically. I have decided not to cover these extras in this tutorial though.

By using our own icons we can create customised workbooks and not be constrained by the standard Microsoft icon set provided.

In this example I have a macro that exports all the worksheets of a workbook to PDF, and I want to assign it to the icon shown below. This icon was downloaded from flaticon.com, a fantastic resource for icons that you can use for your macros.

To insert our icon into a Ribbon of an Excel file we need the Custom UI Editor for Office. This is free to download and if you do not have it already you can download it here – Custom UI Editor for Office.

Open the Custom UI Editor and open the Excel workbook where you would like to add your icon.

You may see some XML code appear as soon as you open the file, but you will probably need to insert some sample XML code to get started.

You can do this by clicking **Insert**, **Sample XML** and then **Custom Tab**.

This code can now be edited to work for you. Change the **label** for the tab, group and then button to what you want to use.

Then enter the name of the image you want to use for the **image** argument. In the example below my image is saved as *analytics-72*. Shortly we will insert this into the Excel workbook.

Finally enter the name of your macro for the **onAction** argument. My macro is called *ExportAsPDF*.

You can copy and paste the relevant lines of code to easily add more buttons, groups or tabs.

**Insert your Image to the Workbook**

With the code now set to add your icon to the Ribbon and run your macro, we need to insert the image into the workbook so that it is there to be used.

Click the **Insert** menu and then **Icons**. Browse and select your icon and it will be added to the file. You can see it on the left. Click the + sign next to the workbook name to expand the list of all added icons.

The problem with extracting UK postcodes is that they are highly irregular. They will be at the end of the full address and can come in a different number of characters e.g. E1 6AX, RM3 8HN and LE41 8JX.

They are not as structured as a US zip code may be and harder to extract. Because of this the formula is intense, but I am going to break it down and explain it in detail.

The formula below is the finished article. If you are not used to writing formulas like this it may seem overwhelming, but we are going to look at it one piece at a time.

To use this formula, simply copy and paste and change the cell references to where your addresses are entered. If you want to know more about how this works, read on.

*=RIGHT(SUBSTITUTE(A5,” “,”*”,LEN(A5)-LEN(SUBSTITUTE(A5,” “,””))-1),LEN(A5)-FIND(“*”,SUBSTITUTE(A5,” “,”*”,LEN(A5)-LEN(SUBSTITUTE(A5,” “,””))-1)))*

The RIGHT function has been used to extract the postcode. This function extracts text from the end of a cell. We can be sure that the postcode is at the end, so this function works for us here.

The Right function requires two pieces of information from us. What text to extract the postcode from, and how many characters in the postcode.

*=RIGHT(the text to extract from,how many characters)*

What we do not know is how many characters are in the postcode of each address. We need Excel to calculate this.

To do so, we will find and mark the start of the postcode in the address. This unique mark can then be used to calculate how many characters in the postcode.

The postcode always starts after the penultimate space of the address. It does not matter how many spaces are in the address, we can be sure that the postcode begins after the second from last space.

The formula below calculates what number space the penultimate space is. So it basically returns the position of the space.

LEN(A2)-LEN(SUBSTITUTE(A2," ",""))-1)

The LEN function returns the number of characters in a cell. The SUBSTITUTE function finds and replaces each space with nothing, essentially removing them.

Altogether, by subtracting the number of characters in a cell without spaces from how many characters including spaces, gives us how many spaces there are.

The -1 is then used to return the occurrence of the second from last space.

This part of the formula actually occurs twice n the full formula as shown below.

*=RIGHT(SUBSTITUTE(A2,” “,”*”, LEN(A2)-LEN(SUBSTITUTE(A2,” “,””))-1),LEN(A2)-FIND(“*”,SUBSTITUTE(A2,” “,”*”,LEN(A2)-LEN(SUBSTITUTE(A2,” “,””))-1)))*

Now that we have found the postcode we want to insert a unique marker so that Excel knows where it is.

In the formula below the SUBSTITUTE function has been added to the previous formula to add an ***** at the start of the postcode (the second from last space).

SUBSTITUTE(A2," ","*",LEN(A2)-LEN(SUBSTITUTE(A2," ",""))-1)

This also occurs twice in the formula.

*=RIGHT( SUBSTITUTE(A2,” “,”*”,LEN(A2)-LEN(SUBSTITUTE(A2,” “,””))-1),LEN(A2)-FIND(“*”,SUBSTITUTE(A2,” “,”*”,LEN(A2)-LEN(SUBSTITUTE(A2,” “,””))-1)))*

In the second part of the RIGHT function the formula below has been used to find the position of the * (our unique marker), and subtract that number from the total number of characters in the cell (LEN function). This returns how many characters are in the postcode.

LEN(A2)-FIND("*",SUBSTITUTE(A2," ","*",LEN(A2)-LEN(SUBSTITUTE(A2," ",""))-1))

I do hope this makes sense. It is a complicated formula if you are a beginner.

If you are interested in seriously improving your Excel formula skills. Check out our online course – Excel Formulas Made Easy – Learn over 100 Formulas.

This blog post uncovers 6 different ways you can find the last row. In these examples the number of the last row is assigned to a variable for use within your procedures.

Are you new to Excel VBA? Learn Excel VBA quickly with this online course.

For these examples the following variables have been declared and the *sht* variable activated.

Dim sht As Worksheet Dim LastRow As Long Set sht = ThisWorkbook.Worksheets("Sheet1")

You may know that using the keyboard shortcut of **Ctrl + the down arrow **key will shoot you to the bottom of a list. The VBA code for the same shortcut is shown below.

This assumes A1 is the first cell of data.

LastRow = Range("A1").End(xlDown).Row

This is a common approach but has its disadvantages. This shortcut finds the bottom of a block of cells. This means that if you have blank cells in a range it will not accurately find the last row.

If you have blanks cells in a range, then you could work around that by starting quite far down a spreadsheet and using the shortcut to go up and hit the bottom (instead of top and down).

LastRow = Range("A100000").End(xlUp).Row

You will need to ensure the starting cell is further than you will ever need. In this example it is row 100,000.

The *UsedRange* property in Excel VBA is the range of filled cells on a spreadsheet.

It is extremely useful that Excel knows this, and we can use this information on a worksheet by using the shortcuts **Ctrl + End** and **Ctrl + Home**.

However this *UsedRange* needs resetting or it may contain outdated information about the sheet. The code below clears the *UsedRange* and then uses it to located the last row number.

sht.UsedRange.Clear LastRow = sht.UsedRange.Rows.Count

The CountA function can be used to count all non-blank cells in a range to find the last row.

Now like the first example, you will need to be careful of blank cells in a range causing a problem.

However in my blog post on creating a macro to remove blank rows from a list, I used this technique for exactly that reason. To find out how big the list is, when the blanks are removed.

LastRow = Application.CountA(Range("A:A"))

If you have set up a named range for your list, this can make it easy to find the last row. In the code below the named range of the list is *Sales*.

LastRow = sht.Range("Sales").Rows.Count

If you have already formatted your range as a table. We can used the table to locate the last row number.

LastRow = sht.ListObjects("Table1").Range.Rows.Count

- Loop Through all the Files in a Folder using VBA
- Count Cells in a Range By their Cell Colour
- Export Multiple Excel Sheets to a Single PDF
- Format Specific Words in a Cell using VBA

blah blah

]]>

This tutorial will show you how to display any symbol though, so you could insert a smiley face, hour glass, aeroplane and much more.

The first thing we need to do is find out the letter or number for the symbol we want to insert. Every symbol from the *Wingdings* libraries has an associated letter or number when displayed in a normal written font such as Calibri or Arial.

To find this out; start by inserting the symbol in a cell on your worksheet. Then select that cell and change the font to Calibri, Arial or some other written font.

The letter or number will now be displayed instead. For example, the smiley face symbol is J, and the hourglass is 6. Importantly for this tutorial, we know the thumbs up symbol is C, and thumbs down is D.

The following formula was written in cell D2 of the worksheet shown above.

=IF(C2>=B2,"C","D")

It tests if the value in C2 (this months sales) is greater than or equal to the value in B2 (last months sales). If it is then display C (remember this is the thumbs up symbol), and if not display D (thumbs down symbol).

Now that we have the IF function showing the correct value, all the cells containing the formula need to be formatted in a font such as Calibri to show the symbol.

In the example shown above, the thumbs up symbol is formatted in green, and the thumbs down symbol in red. This is done using Conditional Formatting.

- Select the range of cells containing the symbols.
- Click the
**Home**tab and then**Conditional Formatting**. - Select
**Highlight Cells Rules**and then**Equal To**. - Enter C in the first box and then select a green font colour from the
**Custom Format**options in the second box. Click**Ok**.

- Repeat these steps to display in a red font if the value is equal to D.

Displaying a different symbol based on the values of your worksheet, and applying automatic custom colours can add a creative wow factor to your spreadsheets.

Depending on the kind of data you work with, there are loads of symbols on offer and they may just have your spreadsheets jumping out of the screen.

The spreadsheet below shows a list of names with the answer in cell D2. *Ross* is the name that occurs the least in that list.

This formula returns the least frequent value from the list in A2:A16. The formula is explained below so keep reading.

{=INDEX(A2:A16,MATCH(MIN(COUNTIF(A2:A16,A2:A16)),COUNTIF(A2:A16,A2:A16),0))}

This formula is an array formula so you need to press **Ctrl + Shift + Enter**, and not **Enter**. This will put the curly braces around the formula. You do not type these.

Within this formula the COUNTIF functions are used to return how many times each name occurs in the list. The COUNTIF functions return the result below;

{2;5;5;4;4;5;4;4;5;2;4;5;4;4;4}

This means that the name in the first cell of that range (A2) occurs twice, 2nd cell (A3) occurs five times, 3rd cell (A4) occurs five times and so on.

The MIN function returns the smallest number from that array, which is 2 in this example.

The MATCH function is then used to search for the position of the first instance of 2 (the least mentioned names position). The result of this is 1, because the first instance of 2 is in the first cell of range A2:A16.

The INDEX function then returns the value which is in that cell (A2). Which in this example is *Ross*. Watch the video below for a visual explanation of this formula.

The INDEX and MATCH functions are awesome when used together for a flexible lookup formula. Find out more at this INDEX and MATCH tutorial.

Seriously improve your Excel Formula skills with our online course. Over 100 formulas covered. Sign Up Now.

]]>There is no real standalone function in Excel to do this, but it can be done. This could be a useful formula to find how many payments, or how many meetings until an end date.

The formula below calculates the number of Fridays between the date in cell A2 and the date in cell B2. The formula is explained below.

=B2-A2-NETWORKDAYS.INTL(A2,B2,16)+1

In this formula the start date is subtracted from the end date to begin with. This will leave us with how many days in total between the two dates.

In the second half of the formula, the NETWORKDAYS.INTL function is used to calculate the difference between the two dates excluding Fridays. This is then subtracted from the current total to leave us with how many Fridays there are.

The 16 in the function specifies to exclude the Fridays. When typing the function a list appears asking which days to exclude.

The +1 is added to the end because the NETWORKDAYS.INTL function calculates whole workdays. For example, you may consider the difference in days between today and tomorrow to be 1 day. NETWORKDAYS.INTL would return that answer as 2 as it uses each day as a whole day. So the +1 is added to counteract that.

I wanted to explain the other technique first as it probably makes more logical sense. However this tip was brought to me by one of my YouTube subscribers and seems to work.

I don’t really know how it works to be honest, but it does.

The NETWORKDAYS.INTL function is used, but in the third argument a string of 1’s and 0’s are used to specify what weekday you want to count. The example below counts the number of Fridays.

The string starts from a Monday. So this can be easily customised to your own requirements.

=NETWORKDAYS.INTL(A2,B2,"1111011")

- Five Awesome Date Functions in Excel
- Timesheet with Different Rates for Shift Work
- How Many Months Between Two Dates

]]>

Well unfortunately Excel does not yet have a Conditional Formatting feature that we can apply to charts. I have great news though. There is a way that we can do it, and it is not difficult.

This blog post will look at two examples of Conditional Formatting with charts so that you get a feel for how to do it. You can then apply the same technique to whatever example you need.

In the first example shown in the image below. We want to be able to highlight the column in each chart that corresponds to the product type selected by the user in cell B3.

To achieve this we first need to add a column to the table which will show the value if the product type is selected by the user, but show the #N/A error if it is not.

The IF function is used to perform this logical test and required actions. The NA() function is used to return the #N/A error if it is not the product type selected. This is done because the chart will not plot error values, so it essentially hides those values on the chart.

The formula below is the one entered into cell C4. It compares the product name against the one selected by the user in B3 of the *Sales By Product* worksheet. It then displays the value in cell B4 if it is a match, or shows the error value if not.

=IF(A4='Sales By Product'!$B$3,B4,NA())

In this example, Music & Sound has been selected by the user.

This data range can then be selected to create a chart. In this example we create a column chart.

Select range A4:C10 and click **Insert** > **Column Chart** and select the 2-D Clustered Column. It should look like below.

The error values are hidden and only the column for the selected product type is displayed.

Double click on the conditionally highlighted column (the orange Music & Sound) and edit the **Series Overlap** to say **100%**.

And our work is done. Continue to apply any further formatting that you think improves the chart.

In this example, we look at highlighting only the columns where the value represents and increase from last year, or last weeks data.

As you saw in the previous example, it is all about the IF function. We use a logical function like IF to perform the conditional test and only show the value if relevant.

Once we have this, we repeat the same chart technique as before to overlap the data series.

The formula below has been entered into cell C4. It compares the sale of this year (B4) against last years sales of the same product. Because the lists are in order largest to smallest by sales value, a VLOOKUP function is used to return the correct sales value.

=IF(B4>=VLOOKUP(A4,$E$4:$F$10,2,FALSE),B4,NA())

The end result looks like below showing only two products have increased sales since last year, or last week.

With this amazing technique you can apply any Conditional Formatting to charts in Excel. All the power comes from the logical function in the table.

Other typical examples might include highlighting actuals against target values, or the max and min values of a chart.

Two Essential Conditional Formatting Tricks You Need to Know

]]>We can find out how many cells by filtering the list by colour, and maybe use the AGGREGATE function to return the count. This is an option. But having to filter the list each time may not be good enough.

Because functions such as COUNTIF cannot count by cell colour, we will need to create our own custom function (also known as User Defined Functions or UDF’s) to get the job done.

- Open the Visual Basic Editor by pressing
**Alt +F11**or by clicking the**Visual Basic**button on the**Developer**tab. - Insert a new module if necessary by clicking the
**Insert**menu and then**Module**. - Copy and paste the code below into the code window (you can put this into the current workbook or the Personal Macro Workbook for global use).

Function COUNTIFCOLOUR(Colour As Range, rng As Range) As Long Dim NoCells As Long Dim CellColour As Long Dim rngCell As Range CellColour = Colour.Interior.Color For Each rngCell In rng If rngCell.Interior.Color = CellColour Then NoCells = NoCells + 1 End If Next COUNTIFCOLOUR = NoCells End Function

You can then use this function like any other function in Excel. The arguments do not appear like normal functions, but everything else is the same.

The user will select the range of cells to use and this is assigned to *rng*.

A For Next loop is then used to loop through each cell of that range checking if it is the colour we are looking for. If so 1 is added to the *NoCells* variable. This is assigned to the function for returning when the loop finishes.

Want to learn more Excel VBA? Check out the complete Excel VBA online course. You will see more examples of User Defined Functions and a whole lot more.