Excel Flash Fill Learns By Example

One benefit of using Microsoft Excel is that there are multiple ways to achieve the desired results. For example, if we want to manipulate text from one cell to use in another, we could use various formulas. But, what if there was a way to do these repetitive tasks without knowing any programming language? I’ll introduce you to Excel’s Flash Fill feature and some input-output examples.

Simple Patterns VS. Complex Formulas

At this stage, you might be confused by my mentioning patterns, but that’s an easy way to think of this feature. We’ll be looking at a data column for commonalities so Excel’s machine-learning techniques can take hold. Let’s look at a couple of examples.

Maybe, someone put people’s full names in one column, but you prefer to have them split into distinct fields. You could split the first and last names using formulas, text to columns wizard, or even extract text from an Excel cell. But, that’s probably overkill if you just need First and Last names.

Another example might be reformatting phone numbers or social security numbers in a specific format. This feature shines when people have inputted multiple phone formats. For example, some people wrap the area code with parentheses and other people just string all the numbers together.

Start With The End in Mind

In the example below, I have a series of US presidents. In Column A, we have the Last name, comma, and First name. And sometimes, we have a Middle name. My preference is to have a separate column for the first name and another for the last name. 

I’ve provided Microsoft Excel with a pattern for John Adams in cells B2 and C2. Notice how I’m not worrying about the comma or middle names. If you need all those fields, I’d suggest the tutorial on how to separate names in Excel.

Excel list of president names.Pin
President list and patterns

Based on my providing a simple pattern, the yellow highlighted cells, Flash Fill has auto-filled cells. In other words, Excel is making an educated guess on what I want in the red box.

President names parsed with flash fill.Pin
Results based on pattern

What Makes a Pattern?

You might be thinking this was too easy for Excel. It just had to look at the cell in column A and grab the first word after the comma and put it in the adjacent column. True, but it also works well, if I alter the president’s names by adding leading spaces, semicolons, removing punctuation, or adding double spaces. See the yellow entries below.

Highlighted examples with different text variations.Pin
Highlighted variation examples

And if I don’t like the results, I have a control where I can Undo Flash Fill.

How to Use Flash Fill in Excel

For these instructions, I’m using Microsoft Office 365. The feature works in any version of Excel 2013 and newer.

In this example, I want the flash fill to use the 3 letter code in the middle of the Program Name and copy it to the Country column. In addition, I want the country code to be uppercase.

  1. Open up your spreadsheet.
Program name with embedded country code.Pin
3 letter country codes in the middle
  1. In the adjacent column, I want to enter my pattern in cell B2
  2. I’ll enter CAN since I want Excel to change the case.
Setting uppercase pattern for the country.Pin
Uppercase country pattern
  1. Press Ctrl + e.

Excel will take an educated guess and fill in the remaining entries in the red boxed area. If you didn’t like the results, you can use the control in C3 to make changes.

Country results and flash fill control.Pin
Uppercase countries and control

Simple Substitutions

Another way you can use flash fill is to substitute values. This can sometimes be easier than using search and replace or learning how to use Excel’s IF function

Let’s take an example where someone has inputted prices and they all end in .00. You prefer to have Excel make the ending zeros be a dash.

Flash fill pattern to substitute text.
Convert 0 to dash

Again, pressing Ctrl + e achieves our results.

Swap 00 to dashes results.Pin

Multiple Patterns & Rearranging Data 

Flash fill can do more than just extract text or change the case. Many years ago, I had to do software testing that required using credit card numbers. You couldn’t just make them up with random numbers because a checksum was involved.

What I could’ve done was find a starting set and then use Excel flash fill to create a new set by rearranging the numbers. In the example below, I want to create new test numbers by shifting the original last group of 4 numbers to the second group of the New Test CC. 

Flash fill pattern for re-ordering data.Pin
Rearranging location of last 4 digits

However, when I use the feature, I don’t get my desired results. I can see flash fill correctly moved the last 4 digits into the second spot on the adjacent cell. However, they added more numbers. I wouldn’t even be able to use these new numbers as they are too long for my purposes.

Flash fill needs yields mistakes.Pin
Flash fill added extra digits

The above incident is an example where you need to provide multiple pattern examples in the adjacent cells. I’ll add another pattern in cell B3 and erase the remaining errors.

Added second pattern example.Pin
Added another pattern example

Now, if I use flash fill, I get my desired results.

Final test credit card numbers.Pin
Good results with additional pattern

Troubleshooting & Tips

Flash fill is a great feature, but it may not work for you straight away. It does need to see enough of a data pattern for the machine learning to kick in.

  1. You can also use Flash fill from the Data tab. 
Flash fill option on Excel ribbon.Pin
  1. Sometimes you need to provide multiple patterns for it to work.
  2. Your adjacent cells should not be blank cells. Don’t have blank columns in between or you’ll encounter an error message that reads:

 “We looked at all the data next to your selection and didn’t see a pattern for filling in values for you. To use Flash Fill, enter a couple of examples of the output you’d like to see, keep the active cell in the column you want filled in, and click the Flash Fill button again.”

  1. Flash fill isn’t dynamic. If I change the underlying data such as the data in Column A above, my cell contents in Column B will not automatically update. I need to invoke Flash fill again.

Hopefully, these Excel flash fill examples have shown the power and ease of the feature. It can be used in countless ways to manipulate text without resorting to more complicated Excel formulas and substrings.

And sometimes, other Excel functions are better for specific tasks. This was the case when I needed to convert month text values to a number. The key is defining your pattern and adding a couple of examples. Sometimes you may have to tweak things but it can make a tedious task more fun.

More Excel Tutorials