Sub topic 13
Flash Fill for pattern-based entry
Flash Fill looks at a column you are typing, works out the pattern from your examples, and fills the rest of the column to match. This chapter assumes you can enter text and formulas, use the fill handle, and navigate the ribbon. It covers how Flash Fill works, how to trigger it, where it fails, and when a formula is the better choice.
What Flash Fill does
Flash Fill is a feature, available in Excel 2013 and later, that extracts, combines, or reformats text by example. You type the result you want for one or two rows. Excel compares your examples with the neighboring data and proposes values for the remaining rows.
Typical jobs include:
- Splitting a full name into first and last name.
- Joining two columns into one, such as a first name and a last name.
- Pulling a piece out of a code, such as the area code from a phone number.
- Changing case or format, such as turning
smith, annaintoAnna Smith. - Inserting fixed characters, such as adding dashes to a number.
Flash Fill ties into the other filling tools in this tutorial. The fill handle copies or extends values by position and step. Flash Fill instead learns a text transformation from your examples.
A worked example
Suppose column A holds full names and you want the first names in column B.
| Cell | Content |
|---|---|
| A1 | Full name |
| A2 | Anna Smith |
| A3 | Luis Ortega |
| A4 | Mei Chen |
| A5 | Priya Nair |
| B1 | First name |
Follow these steps:
- Click B2 and type
Anna. Press Enter. - In B3, start typing
Luis. After a letter or two, Excel shows a gray preview of the suggested values down the column. - Press Enter to accept the preview. Column B fills with
Luis,Mei, andPriya.
If no preview appears, use one of the manual triggers in the next section.
Ways to trigger Flash Fill
You have four ways to run it. The result is the same.
| Method | How |
|---|---|
| Automatic preview | Type an example, then start typing the second one. Press Enter to accept. |
| Keyboard shortcut | Type an example in the first row, select the next cell in the column, and press Ctrl+E. |
| Ribbon | On the Data tab, in the Data Tools group, choose Flash Fill. |
| Fill menu | On the Home tab, choose Fill, then Flash Fill. |
Ctrl+E is the fastest in practice. You type one example, move down one cell, and press Ctrl+E.
Requirements for it to work
- The examples must sit in a column next to the source data, with no empty column between them. Excel looks at adjacent columns for the pattern.
- The source data should have a header row, or at least a clear start. A header above the output column helps Excel recognize the table.
- Automatic suggestions must be turned on. Check File, Options, Advanced, and under Editing options make sure "Automatically Flash Fill" is selected. The shortcut and the ribbon command work even if the automatic preview is off.
How Flash Fill finds the pattern
Excel does not ask for a rule. It tries to infer one from the examples you gave and the cells beside them. Understanding this explains most of its mistakes.
Here is the model:
- You enter one or more examples.
- Excel looks at the cells in the same row to the left and right of your example.
- It searches for a consistent transformation, such as "take the text before the first space" or "take the first letter of the first word and the whole second word".
- It applies that transformation to every row in the block of data.
The important point is that one example may fit several rules. If you type Anna for Anna Smith, the rule could be "text before the space" or "first four characters". With only one example, Excel picks one. A second example, or a different type of row, narrows the choice.
More examples
Combine columns
With first names in A and last names in B, type Smith, Anna in C2 for the first row and press Ctrl+E in C3. Excel builds Last, First for every row.
Extract part of a code
Given product codes like AB-4821-NY in column A, type 4821 in B2 and press Ctrl+E on B3. Excel extracts the middle segment.
Reformat numbers
Given ten-digit phone numbers like 5551234567, type (555) 123-4567 in B2 and press Ctrl+E on B3. Excel inserts the brackets, space, and dash.
Change case
Given anna SMITH, type Anna Smith and press Ctrl+E on the next row. Excel applies proper case based on your example.
Flash Fill output is static
This is the main thing that separates Flash Fill from a formula. The cells Flash Fill creates hold plain values, not formulas. If you later change a source name in column A, the value in column B does not update.
Compare the two approaches for extracting a first name.
B2: =LEFT(A2, FIND(" ", A2) - 1)
B3: =LEFT(A3, FIND(" ", A3) - 1)The formula recalculates whenever A2 or A3 changes. Flash Fill gives you the same result once, with no link back to the source.
Use this table to choose:
| Situation | Better choice |
|---|---|
| One-time cleanup of an imported list | Flash Fill |
| Source data will keep changing | Formula |
| Pattern is irregular and hard to describe | Flash Fill, then check the results |
| You need an audit trail of how a value was built | Formula |
Edge cases and failure modes
Flash Fill is a guess, so it can guess wrong. It does not warn you when it does.
Inconsistent source data
If some rows have a middle name and others do not, a rule based on the first space still works for first names. A rule for last names does not. Anna Maria Smith and Mei Chen need different handling. Excel may return the middle name as the last name for some rows.
Missing values
If a source cell is blank, the output for that row can be blank or can be wrong. Scan rows with gaps first.
Numbers that look like text
Flash Fill often returns text. A result such as 4821 may be stored as text, so it left-aligns and does not sum. Convert it with Text to Columns or by multiplying by 1 in a helper column if you need a real number.
Leading zeros and dates
If you type 00123, Excel may treat the example as a number and drop the zeros. Format the output column as Text before you start. Dates can also be reinterpreted when the example looks like a date.
Too little context
With a single example and a varied column, Excel may produce no preview at all, or a wrong one. Add a second example in a different row, then run Flash Fill again.
No preview and no change
If Ctrl+E does nothing, Excel could not find a pattern. Check that the output column is directly beside the data, that your examples are correct, and that the source column contains consistent values.
Fixing and undoing a Flash Fill
After Flash Fill runs, a small Flash Fill Options button appears beside the filled cells. Its menu has these choices:
- Undo Flash Fill, which removes the fill.
- Accept suggestions, which keeps the preview.
- Select all changed cells, which selects the cells Flash Fill filled so you can review them.
- Select all unchanged cells, which selects the rows Excel did not fill.
The last two choices help you audit results. Selecting the unchanged cells shows you which rows did not match the pattern.
To correct a wrong result, fix one wrong cell by typing the right value, then run Flash Fill again. Your correction acts as a new example. Ctrl+Z also undoes the fill in one step.
Practical habits
- Give each output column a header.
- Keep the output column next to the source data.
- Give two or three varied examples when the data is irregular.
- Format the output column as Text first if you need leading zeros.
- Spot check the first, last, and any unusual rows.
- Prefer a formula when the data will change.
Exercise
Column A contains codes like INV-2045-US, INV-3310-UK, and INV-1187-DE. You want only the four-digit number in column B. Describe how to get it with Flash Fill, and name one reason you might choose a formula instead.
Show answer
Type 2045 in B2, select B3, and press Ctrl+E (or start typing 3310 and press Enter on the preview). Excel fills column B with 2045, 3310, and 1187. Check the results afterward. A formula such as =MID(A2, 5, 4) is the better choice if the codes in column A will change, because Flash Fill output is static and does not update when the source changes.
Exercise
You use Flash Fill to turn 5551234567 into (555) 123-4567, but the result for one row is missing its leading area code digit. What are two likely causes and one fix?
Show answer
Likely causes are that the source cell in that row has a different length or format than the others, such as a stored number with a missing digit or extra spaces, or that Excel inferred a rule from too few examples. To fix it, correct that row's output by typing the right value, then run Flash Fill again with Ctrl+E so the correction becomes an extra example. Clean the source cell first if it is malformed.