Tag Archives: Excel

Nail Down That Date!

Passing a spreadsheet around between organizations has a hidden problem; one that can easily make trouble. And the trouble comes, not from the spreadsheet, but from the default date setting on the computer.

Excel uses the default date setting to interpret the order of date information. Whether its’ Month-Day-Year or Day-Month-Year, or even Year-Month-Day, that information comes from the OS date settings. These are settings that we don’t often think about once we’ve set them. And typically, they are the same throughout an organization.

But take the spreadsheet you’ve designed, that uses Month-Day-Year into a Day-Month-Year organization, and all sorts of problems crop up.

The first problem is that you might not notice immediately; if July 6, turns into June 7 – that might not jump out at you as a problem. If you are lucky, you’ll spot something weird about the 12th of Month 21 …

So how do you nail down those dates so they can’t shift? One strategy is to break up your date entry into your preferred format, and then rebuild the date using the DATE function.

The syntax for the DATE function is =DATE(year, month, day)

The Date Function
Using the Date function to reassemble a date from separate cells

Here you can see the DATE function is building a date from the values in three separate cells: A3, B3 and C3 and the formula looks like this =DATE($C3,$B3,$A3)

Another advantage of this strategy is that Data Validation can be applied to these cells; ie the day column can be restricted to whole numbers between 1 and 31, the month column to whole numbers between 1 and 12 and the year column as well. In the sample file I’m using, the column holding the complete date (D) is hidden from the user. They will only see columns A thru C. The complete (and correct) date is referenced in formulas.

An alternate strategy would be to use the DATE function to extract the correct order from a whole date typed into a cell. In this case you would need to rely on the users to enter the date consistently regardless of their date system. I would recommend a custom date format be applied and a comment to tell the user what the required date format is. Breaking the date up avoids this reliance on the user’s compliance.

Eat Your Waffles

Ok, don’t eat the waffle chart

In a previous post, I discussed making a Button Bar Chart. That whole process really inspired me to think about simplified charts for presentations.

Which got me thinking about Waffle Charts.

4 category waffle chart
Note how the smallest group stands out

Waffle charts are excellent for looking at data sets where the smallest numbers are the important ones. You can use colour (as I have above) to make those numbers stand out.

But oddly, I don’t see people using a lot of waffle charts in their presentations. And there is no template for a waffle chart in Excel.

You can find some interesting ideas about building Excel waffle charts for dashboard purposes and I recommend this article to you: Interactive Waffle Charts in Excel

However, I was looking for something different. Something that wouldn’t have me counting and colouring cells manually (shudder).

Building the Waffle

I chose to build the waffle chart using a series of conditional formatting rules. The first step was creating the formula to count the cells of the waffle.

Waffle chart base formula
Counting the cells in a 100 grid waffle

In case the picture is a bit small, the formula used here is:
=(MOD(ROW()+8,10)*10)+(COLUMN()-2)+1

This uses the row and column position of the cell to count from 1 to 100 in a 10 by 10 grid.

I then built on that base formula with this monster formula:

=IF((((MOD(ROW()+8,10))*10)+COLUMN()-1)<=’5 Category Waffle’!$A$2,’5 Category Waffle’!$A$2, IF((((MOD(ROW()+8,10))*10)+COLUMN()-1)<=(‘5 Category Waffle’!$A$2+’5 Category Waffle’!$A$3),’5 Category Waffle’!$A$3, IF((((MOD(ROW()+8,10))*10)+COLUMN()-1)<=SUM(‘5 Category Waffle’!$A$2:$A$4),’5 Category Waffle’!$A$4, IF((((MOD(ROW()+8,10))*10)+COLUMN()-1)<=SUM(‘5 Category Waffle’!$A$2:$A$5),’5 Category Waffle’!$A$5, IF((((MOD(ROW()+8,10))*10)+COLUMN()-1)<=SUM(‘5 Category Waffle’!$A$2:$A$6),’5 Category Waffle’!$A$6,0)))))

The sheet BTW is called 5 Category Waffle.

5 category formula
The 5 category waffle formula result

The formula checks the position number of the cell generated by the base formula and sees if it is less than or equal to the number of values in each category in column A. It then returns the value of the category in each cell.

Because I wanted to put symbols in the cell like these examples.

talking head icon used in waffle chart
Talking Heads waffle chart
bomb icon waffle chart
Bombs waffle chart

I took that monster formula and made it into a named formula.

 

 

This made building the conditional formatting rules much easier to do(simply because the conditional formatting dialog is so cramped).

Lastly, I built a series of conditional formatting rules to change the background colour of the cell based on the value returned by the formula. For the waffles using symbols, the rule formats the colour of the font, instead of the background.

A couple of additional pointers

  • To create a perfect grid, switch the view in Excel to Page Layout View. Page Layout View uses the same measurement scale for both row height and column width.  Set your measurements here.
  • For the symbol waffles, use the File> Options>Advanced> Display Options for this worksheet and turn off the display of gridlines. That way when you copy the waffle, the gridlines will be invisible.

 

Button Bar Chart

Simple or Complicated?

Simple or complicated? It’s been my observation that anyone can make a subject sound complicated – but it takes real understanding of a topic to simplify it in a way that is meaningful.

This is why, when I saw this sample slide below from designer Julie Terberg, I sat up and paid attention. Here is a wonderful example of a chart that is simple in a beautiful and useful way. Immediately, you can see that an audience would find this chart easy to read and understand

Button Bar Chart by Julie Terberg
Julie Terberg’s Button Bar Chart from her #SlideADayProject project

I paid even more attention when I saw the way that Neil Malek put together an Excel version of the chart. Neil introduces a clever technique using shapes in data labels.  Here is the YouTube video:

Unfortunately, Neil’s clever technique is only available in Office 2016. I wanted to build the chart in Office 2010, for the benefit of my clients still using 2010.

Button Bar Chart Slide example
Button Bar Chart Slide, in PowerPoint 2010

I think that in the end, I succeeded. If you are interested in building this chart, and like me you are restricted to Office 2010, then I have a few pointers for you.

Button Bar Chart Pointers

  • Data Labels in 2010 can not use shapes. Instead, I tweaked the Shadow setting for the label, by setting the colour to match the fill on the label and the size to 150%. I left all other settings to zero. Shaping the label this way means that you can never achieve the circle that Julie used in her example. Instead, the best you can do is a lozenge shape. You can modify this when you change the font size in the label.
  • But once you’ve used the Shadow to enlarge your button, you can’t use it to shadow the data label. I solved this problem with an old fashioned solution. I made two charts (a 2016 and a 2017 chart). The two charts are grouped together.  Each chart has a data label for the year and a data label for the shadow. In the example below those labels are using the 1 values. The column labelled 2016 value is the length of the bar.
Where the data for the chart comes from
Button Bar Chart Data layout
  • The Shadow column must proceed the 2016 column or your shadow will wind up on top of the 2016 label. Also format your labels in that order as well, or the shadow will temporarily be on top of the 2016 label.
  • Format your shadow and label to the same font size.
  • The Chart Element selector on the Format Tab of the Chart Tools ribbon is your friend. Its’ really the only reasonable way to select the shadow data labels once they are under the visible label.
  • Link the label text to the cell in in Excel by using the formula bar and typing in the linking formula to the cell. This allows you to update the chart, by changing the text in the cell. A bit finicky to set up; but it will save a ton of time in the long run.
  • The best way to take this chart into PowerPoint is by copying/pasting the chart – as an image. Which means that you’ll need to presize the chart in Excel, so that text is not distorted by resizing once it is pasted into PowerPoint. Again, its a bit finicky – but worth it.
  • In PowerPoint, I created a layout, with text placeholders on the left and bottom of the slide.

    Layout has placeholders
    Layout has text placeholders on left and bottom of slide

All in all, a pretty reasonable version of Julie’s stellar design.

If you want to follow Julie Terberg and Neil Malek on Twitter, you’ll find them here.

Excel – Total at the Top

It’s that time of year again. Tax time. Now that I’ve made you sad, lets check out a formula which is very useful when adding up long columns of numbers (deductions anyone?)

Column of numbers, with accompanying total
Put the sum of the column at the TOP of the page, making it easy to find

When you have long columns of numbers of irregular length, it is often easier to have the totals display at the TOP of the page. That way, you don’t have to scroll all over the place to find them. The other advantage of this formula is that you can use it to keep an eye on your total as it accumulates, since you don’t have to know how many rows long the column will be.

The formula here is =SUM(OFFSET(A1,1,0,COUNT($A:$A),1))

Where the OFFSET & COUNT functions are used to create the range that will be summed.

The syntax for OFFSET
OFFSET(reference, rows, cols, [height], [width])
OFFSET(A1,1,0,COUNT($A:$A),1)

  • A1 is the reference cell,
  • Rows – the range begins 1 row down from A1,
  • Cols – the range begins in the same column 0,
  • Height – the number of rows to be included are counted using the COUNT function, COUNT($A:$A) counts the cells in Column A with numbers in them
  • Width – is set to 1 column (column A) wide

I have to say there is something very satisfying about seeing that total increase as each number is entered in the column.

featured image by
Antoine Dautry

Generating Random Numbers and Letters

Need to generate a random number? Excel has two formula variations that can do that for you.

The first is RAND, it generates a random value between 0 and 1. But if you need larger values, try RANDBETWEEN.

RANDBETWEEN generates random numbers between a bottom and top value that you specify.

Lastly, if you need to generate a random letter value – try this formula: =CHAR(RANDBETWEEN(65,90))

In this formula the CHAR function returns the character symbol specified by a number. Letters A-Z are between 65 and 90.

 

 

Flash Fill

Flash Fill is a new tool introduced in Excel 2013. Its a simple tool to handle a frequent problem. You have a small set of data and you need to break it apart into separate columns or join separate columns of data together.

Previously, I would have handled it with a series of text functions in Excel (LEFT, RIGHT, MID) combined with FIND and LEN if the data was complex enough. But if the data set is small, writing a formula sometimes seems like an overly complicated answer to a simple problem (why not just retype?).

Now Flash Fill is stepping in to help you handle this problem. If you give it a series of data (column orientation only) and an example of the pattern you want to extract, it will extract the data for you.

Flash Fill in action
Flash Fill captures the first names only from the adjacent column

You can see once the second name is typed in the column adjacent to the list of full names, Flash Fill is able to see the pattern and offer all the first names in the list. Pressing enter autocompletes the action and the names are filled in. To do this, there can not be more than two blank columns between the source data and the resulting column. You can use the Ctrl + e shortcut to start flash fill.

Flash Fill Icon
Note the Flash Fill Icon displaying after the Ctrl + e shortcut was used.

You can click the Flash Fill icon to display the menu, accepting the suggestions will have all the names autocomplete.

The Flash Fill menu will display if the icon is clicked
The Flash Fill Menu

Here is an even trickier scenario, in the list above some names have two middle initials. Using the “default” flash fill means only the second initial will display in those names. However if I return to any of the names on the list (with two initials) and correct the example to two initials, all of the two initials examples will be extracted.

Two initials with Flash fill
Flash Fill double initial example

I find that seriously impressive.

I can split data in a cell into multiple columns and I can also use Flash Fill to join multiple columns of data together.

Flash Fill concatenation
Joining separate columns using Flash Fill

The same technique used above. Note that I’ve been able to add commas and periods to the text as well.

Formatting via Flash Fill
Using Flash Fill to apply formatting

In the same way, I can use Flash Fill to apply formatting, in this case putting a space between the first and second part of a postal code. You can also use it to format telephone numbers and date information.

A little bit of history – lost … and found

Excel has been around for decades, so it isn’t surprising that there are many features tucked away under the hood. What is surprising is when a useful feature is lost and only careful archeology can bring it back to life.

Excel 4.0 had a rudimentary macro language, mostly using excel formula approaches to building functionality. This was replaced by the VBA programming language. But there are still useful little items tucked away in this early language that haven’t been replaced.

One of these is Get.Cell.

Get.Cell had a boatload of switches that allowed the user to pull information about the cell formatting and contents and most of these have been replaced by the Cell and Type functions in Excel.

But one piece of information that Cell and Type can’t tell you is whether your cell or cells contain formulas vs values and sometimes this is a very handy thing to know at a glance. For example, if you build a spreadsheet using formulas to estimate amounts; but then start to drop in values as more concrete information becomes available.

In this situation I like to format cells containing formulas differently from the cells containing values, so that I can see at a glance where my estimates are. Its’ handy to have the formatting change automatically, so I don’t have to remember what my rules are weeks or months later.

This is where Get.Cell shines. The syntax I’m going to use is

=GET.CELL(48,A1) – where A1 is the cell I’m going to reference.

The trick here is that Get.Cell is NOT entered in a cell, but instead as a named formula. After creating the named formula, I can reference it while applying conditional formatting. In this way, when the type of content in the cell changes the conditional formatting automatically updates.

Using a named formula in Conditional Formatting - dialog box
Using a named formula in Conditional Formatting

Where does one find information about the Get.Cell function? Not from Microsoft or at least not easily from Microsoft.

Try this post https://www.mrexcel.com/forum/excel-questions/20611-info-only-get-cell-arguments.html   to see the possible switches for Get.Cell

 

 

Highlighting the Current Year

Here is a version of a spreadsheet that I’ve been using for a couple of years to track and plan capital purchases. A number of people review this spreadsheet and I want to make it as easy as possible for them to read the spreadsheet. You’ll notice that the Budget year is highlighted in green and items being purchased in that year are highlighted as well. This is accomplished with our friend conditional formatting and the following spreadsheet functions:

  • ADDRESS
  • ROW
  • COLUMN
  • MATCH
  • INDIRECT
  • ISBLANK
Spreadsheet with automatic highlighting
Capital Budget Spreadsheet – note the row and column (year) highlights

This spreadsheet makes use of a helper column of formulas. Rows where the value equals TRUE are highlighted.

The Helper column holds formulas
The Helper column holds formulas

Cells give a value of TRUE when there is a value for that row in the Budget Year selected in cell A1. You can see that 2017 has been selected as the Budget Year and that rows 9 and 20 have a value for that year and are highlighted as a result.

This is the formula that returns the value

=ISBLANK(INDIRECT(ADDRESS(ROW(),MATCH($A$1,$F$2:$AU$2,0)+5,3,TRUE)))=FALSE

Working from the interior of the formula outward.

MATCH($A$1,$F$2:$AU$2,0)

This looks for a match between the value in A1 and the Budget year headings which start in cell F2 and go to AU2 (the year 2033, which is incredibly optimistic – but that is another story). MATCH returns the number of the first item in that array of cells that matches the value in A1. This is why even though there are two columns for every year (a Budget column and an Actual column) MATCH will only return the Budget column, as it is the first value to match.

So the result of MATCH($A$1,$F$2:$AU$2,0) is 9

However, if I actually want to capture the column I need to to add 5 to compensate for the fact I have 5 columns (A-E) before column F and the year headings begin.  This is why I’m adding 5 in the formula.

MATCH($A$1,$F$2:$AU$2,0)+5 =14

In the next step I use ADDRESS and ROW to capture the address of the cell I’m testing.

ADDRESS(ROW(),14,3,TRUE))

ROW() captures the value of the row of the cell where the formula is written. If the formula is in A3, then row() returns 3.

ADDRESS turns the cell address of the referenced cell (not its’ contents). In our example; ADDRESS(3,14,3,TRUE)=”$N3″

The ISBLANK function in the next step has a bit of a hiccup with that “$N3” string, so we use INDIRECT to convert that string to something ISBLANK can understand.

Finally, ISBLANK is used to test if there is a value in the referenced cell or not. If there is nothing in the cell ISBLANK = TRUE.

If ISBLANK = TRUE, then the last portion of the formula looks like this: TRUE does not equal FALSE, so the result of the formula in cell A3 is FALSE.

I could have put that formula into the conditional formatting dialogue – but for clarity and ease of working I choose to make the helper column instead.

In the conditional formatting dialogue I’ve used the following formula =$A3=TRUE

I’m using a simpler version of the formula in the conditional formatting dialogue to highlight the year.

=MATCH($A1,$F$2:$AU$2,0)+5=COLUMN()

In this case I find the column number of the year and test to see if it matches the column number of the current cell. If it does then the cell receives a green highlight fill.

Cell A1 uses Data Validation to offer the user a nice drop-down list of years.

Excel: Frozen

Freezing panes is a basic tool to make a large spreadsheet easier to work with. In my social media spreadsheet I like to freeze the header row into position. Then no matter how far I scroll down the sheet, the columns are labelled.

To turn on frozen panes, select the cell below the row & column you wish to freeze into position. Since I don’t want to freeze any columns, I select cell A2.

Freezing Panes using the Active Cell position
Freezing Panes using the Active Cell position

Select the View Ribbon, Click on the Freeze Panes button, and choose Freeze Panes (or Freeze Top Row in this scenario).

Freezing Panes Results
Freezing Panes Results

Now you can scroll for hundreds of rows, and each column is nicely labelled – no guessing!

Excel: Select Visible (2)

The Select Visible Cells Only button on the Quick Access Toolbar
The Select Visible Cells Only button on the Quick Access Toolbar

The Select Visible Cells Only function is so useful, I like to add it to the Quick Access Toolbar (QAT) in Excel. These instructions are based on Excel 2010, but will be similar in all current versions of Excel.

Quick Access Toolbar Customization
Quick Access Toolbar Customization

The Quick Access Toolbar starts in the top right corner of the Excel window.  The customize button is circled in red. Clicking on that button displays the menu shown below.

Move the QAT under the ribbon
Move the QAT under the ribbon

The first change I like to make is to its’ position. I like to move it under the Ribbon, since there will be more room for buttons there. Over time I tend to fill the QAT up with frequently used tools.

After I move the QAT below the ribbon, I go hunting for useful commands to add.  Click the More Commands… option and the Customize the Quick Access Toolbar dialog opens up.

Customize the Quick Access Toolbar - Popular Commands
Customize the Quick Access Toolbar – Popular Commands

The dialog box defaults to Popular Commands.  Try scrolling through this list and find the Format Painter. Press the Add button, to add it to the Quick Access Toolbar. This is a useful tool to have at hand!

By clicking on the Choose commands from drop-down list, a selection will be displayed.

Drop-down list of source commands.
Drop-down list of source commands.

Select All Commands from this list. Hundreds of Excel commands will display, and this is where it is useful to know the name of the command you are looking for. Scroll until you find Select Visible Cells.

Finding the Select Visible Cells command
Finding the Select Visible Cells command

Select it, Click on the Add button, and click OK.

Simply select the cells you wish to copy and press the Select Visible Cells button. Paste your information and only what you see will be pasted.