Search Not Just Numbers

Friday, 6 October 2017

Excel Tip: Use the HYPERLINK function to link to a cell on another worksheet

The HYPERLINK function can be very helpful in Excel for creating multiple links to websites, other documents or cells in the current document based upon cell data.

You can create a static hyperlink without it, but if you have a list of URLs or file paths, the function can allow you to dynamically create links to them without having to create each one individually and with the added advantage that the links will update if the underlying data is edited.

It's a really simple function to use, but the Excel help function is very vague on how to use it to link to cells on another sheet in the same workbook.

First of all a quick introduction on how to use the HYPERLINK function.

It's syntax is:

=HYPERLINK(Link address,[Friendly name])

Where the Link address can be a file path, a cell location or a URL. The Excel Help on the function gives a useful list of the syntax for each of these (except for a cell on another sheet!).

The Friendly name is optional and is the string you want to appear as the hyperlink. If this argument is not entered, the Link address will show in the cell.

Take a look at the spreadsheet below:

The hyperlinks in column C are created using the HYPERLINK function, the formula in C2 being:


This can then be copied down the column. Columns A and B could be hidden or on a different sheet making the hyperlinks a user-friendly way of navigating to the websites.

Now let's say we had a Sales workbook with a sheet for each department and a Summary sheet listing all departments' sales, with the sales total being in cell H7 on each sheet. Let us also assume that the department name is used as the tab name for each sheet.

We want the summary sheet to show three columns as below:

...with column B showing the sales total in cell H7 on each of the sheets, and column C being a hyperlink to cell H7 on each of the sheets.

We can use the INDIRECT function in B2 as follows:


This can then be copied down.

This is the same as writing


Except we have used ampersands to concatenate the preceding single quote ('), the contents of cell A2 (Retail) and '!H7.

The reason for placing the single quotes around the tab name is to allow for spaces in the tab name.

You would then think that you could enter the following in cell C2:

=HYPERLINK("'"&A2&"'!H7","Visit "&A2)

NB: INDIRECT is not needed here because the HYPERLINK function expects a link in the form of a string.

or even:

=HYPERLINK("'Retail'!H7","Visit Retail")

...but each of these return an error when you click on the hyperlink.

What the Excel Help doesn't tell you is that when referencing worksheets in the same workbook with the HYPERLINK function, you need to prefix the sheet name with a #.

NB: If you enclose the sheet name in single quotes then the # comes before the single quote.


=HYPERLINK("#'Retail'!H7","Visit Retail")

...will work. As will, for our example:

=HYPERLINK("#'"&A2&"'!H7","Visit "&A2)

...which can be copied down the list.

If you enjoyed this post, go to the top of the blog, where you can subscribe for regular updates and get two freebies "The 5 Excel features that you NEED to know" and "30 Chants for Better Charts".

Wednesday, 27 September 2017

Excel Tip: How to evaluate individual parts of a large formula

Just a short but very useful tip this month. But before we start, I'd like to thank those readers who donated to Macmillan Cancer Support when I ran the Great North Run earlier this month. All donations are much appreciated and the page is still open for a little while longer if anyone would still like to donate.

Have you ever written a long formula that isn't giving the result you'd expect (or is returning an error), but you don't know which part is the problem? If you've ever written a long formula, then it's a fair bet that you have!

Well, there's an easy little trick that you might not be aware of, that can make this much easier to investigate.

The problem:
Say you have a formula such as:


It is returning 0 and you don't think it should be. This could be because A2 is 3 or less, or because the IF function is returning an error and you don't know which.

The solution:
You can evaluate any expression within the formula individually, using the F9 key.

Within the cell or formula bar, highlight the section of the formula that you want to evaluate. In this case it would be useful to see whether the output of the IF function alone is a zero or an error, so highlight the IF expression:


and press the F9 key. The formula will now show the result of the selected expression within the full formula, rather than the expression itself, e.g.


or maybe


You can do this with as many expressions within the formula as you want, as long as you highlight an expression that on its own would return a result.

In this formula you could have alternatively evaluated A2 or A2>3.

IMPORTANT NOTE: When you have finished doing this, leave the cell by pressing Esc rather Enter so that you do not overwrite the expressions with the results.

This is a simple formula for illustrative purposes, but if you have a really long complex formula, this tool can be invaluable.

If you enjoyed this post, go to the top of the blog, where you can subscribe for regular updates and get two freebies "The 5 Excel features that you NEED to know" and "30 Chants for Better Charts".

Friday, 18 August 2017

Excel Tip: An introduction to SUMPRODUCT and why you should learn it

Let me start with an apology for leaving it so long without a post. It's been a busy time work-wise and, in addition, I've taken up running to finally lose the excess weight and run the Great North Run half marathon next month. After spending the last 20 years or so doing very little exercise while sitting in front of a computer screen, I decided I had to do something about it - and raise some money for a good cause along the way!

OK! Excuses over! I've got a very powerful but often misunderstood function to tell you about.

On the face of it, SUMPRODUCT does a very simple thing, it multiplies arrays together and sums the results. Unless you're a serious mathematician, you're probably thinking that this is not something you've ever had a desire to do! But bear with me.

First of all, here is a simple explanation of how it works:

=SUMPRODUCT({5,6,4},{7,4,12}) returns 107 because:

You can enter up to 255 arrays like this (as long as they are all the same size) and SUMPRODUCT will multiply them then sum the totals as above. That's basically what SUMPRODUCT does. Now let's look at why this is very useful.

First of all, the SUMPRODUCT function allows you to work with arrays without entering the function using Ctrl+Alt+Enter, which means that you don't run the risk of accidentally clicking into the cell and clicking enter, then wondering why your array formula has stopped working. If you don't know what an array formula is ignore this point, as you don't need to worry about it with SUMPRODUCT. If you do, then you'll know what I'm talking about!

More importantly, the arrays entered into SUMPRODUCT can be formulae that result in arrays. The formula above could have been entered as:


if cells A2, A3 and A4 contained 5,6 and 4 respectively and cells C2, C3 and C4 contained 7, 4 and 12.

But we could also (say) add 1 to each value in the first array before multiplying by entering:


resulting in 130  - as ((5+1) x 7) + ((6+1) x 4) + ((4+1) x 12)) = 130.

You're probably still saying, "So what?", but here's where it gets useful.

These formulae can use other Excel functions and, even more usefully, conditions that return arrays of Trues and Falses (converted into 1s and 0s).

Let's say that in the following data, we need to know the total quantity of product A sold in the North:

We could use SUMIFS as follows:

=SUMIFS(C2:C8,A2:A8,"North",B2:B8,"A") which returns 38.

Or we could use:

=SUMPRODUCT(--(A2:A8="North"),--(B2:B8="A"),C2:C8) to return the same answer.

This works as follows...

The formula (A2:A8="North") results in the array:

{TRUE,FALSE,FALSE,TRUE,FALSE,FALSE,TRUE} because these are the 7 results of the formula (A2="North" is TRUE, A3="North" is FALSE, etc.)

By placing the double minus (--) in front of the formula, it forces this to return 1s and 0s instead of TRUEs and FALSES, i.e.:


Our SUMPRODUCT formula therefore arrives at the same answer as the SUMIFS because the three arrays we are multiplying are as follows:

By multiplying the two arrays (A2:A8="North") and (B2:B8="A") after converting them to 1s and 0s, the result will only be a 1 if both conditions are true (as if either returns 0, we will be multiplying the other by zero).

Incidentally, if we don't multiply this by the C2:C8 range we can use this as an alternative to COUNTIFS



is the same as:


But why would you want to use this instead of SUMIFS, or COUNTIFS?

Well, SUMPRODUCT is a lot more flexible.

Let's say we wanted to know total sales value, rather than quantity.

We can't do this with SUMIFS without adding a new column (being column C x column D) and applying the formula to that, however with SUMPRODUCT we can just multiply by column D right in the formula:


or let's say we wanted total sales of product A for North and South:


Here we have added the two arrays together (-- is a +) - which will return a 1 if  column A is EITHER North or South, as one of the columns will be 1 if this is true whereas if it is not, both columns will be 0.

These are still pretty simple uses of the function, but hopefully this is enough to illustrate that they can go far beyond the capabilities of SUMIFS and COUNTIFS.

If you enjoyed this post, go to the top of the blog, where you can subscribe for regular updates and get two freebies "The 5 Excel features that you NEED to know" and "30 Chants for Better Charts".

Wednesday, 5 April 2017

Excel Tip: Look out for this when you use PivotTable filters

Regular readers and clients will know that I'm a big fan of PivotTables. If you format your data into a table format, you can create all sorts of reports quickly, easily and flexibly using them.

In this (short) post, I want to highlight a little trap to watch out for when you filter a PivotTable - particularly if you are filtering out items, such as blanks for example.

On any of the Row, Column or Report Filter fields you can apply a manual filter by ticking (or unticking) individual entries.

In this field I have filtered out the blanks by unticking "(blank)" and leaving everything else ticked. This is exactly the kind of situation that can lead you to fall into the trap.

To understand the problem, you need to think about how a PivotTable works.

The entries in the PivotTable come from the data itself. So this list only includes the Job Descriptions that currently appear in the data (and possibly some that used to, depending on your settings), so the list above may not be comprehensive in future, as new job descriptions appear in the data.

Let's say a new job description of "Clean Fridge Freezer" appears in the data.

Our intention above was to exclude (blank), but Excel doesn't know this. We could just as easily have meant to only include "Clean Oven", "Clean Oven and hob", "Clean Range" and "Clean Range and Fridge Freezer".

So should "Clean Fridge Freezer" be included in the filter or not? We have not given Excel any clue on this, but Excel needs to do something with it, so there is a default position.

By default, Excel assumes that we have pro-actively ticked the things we want to include - which seems a perfectly reasonable assumption, but if that is true, then "Clean Fridge Freezer" hasn't been ticked, so should not be included.

In our example where we were essentially "unticking to exclude", as opposed to "ticking to include", we need to tell Excel this. Fortunately, this is a simple process.

We just need to change a setting in the Field Settings for this field (Job Description in our example), which can be accessed by right-clicking on the Field itself in the PivotTable (or left-clicking on the field in bottom section of the Field List) and choosing Field Settings.

We then need to tick the box to "Include new items in manual filter":

Once this is ticked, new items will be included by default (just for this field). Note that this setting will not change the selection currently in place, so if you hadn't ticked it when you set the filter up and only discover this when a new item isn't included, you will still need to manually tick the new item. However, all future new entries will be automatically ticked.

If you enjoyed this post, go to the top of the blog, where you can subscribe for regular updates and get two freebies "The 5 Excel features that you NEED to know" and "30 Chants for Better Charts".