Excel Tables have been around for a decade now (they are introduced in Excel 2007), and yet, very few people use them. They are versatile, easy and elegant. At Chandoo.org, we celebrate Tables all the time. If you have never used them, start with below tuts.
- Introduction to Excel tables
- How to use structured referencing
- Tables and Relationships in Excel
- Using lookups and other formulas with Excel tables
- Simple way to get absolute references in Tables
- Customizing table styles for awesome usability
While tables are super helpful, they do come with some limitations. Today let’s examine one such unique problem and learn about an elegant solution.
Table Relative Reference Problem
Imagine you are the machine supervisor at Mighty Machine City Inc. Although your machines are mighty, sometimes they do fail. To keep track of which machines are under repair, you maintain a repair log in Excel. Since you heard Tables are mighty, you thought,
‘Gee whiz, I might as well use tables to maintain the repair log. Chandoo says tables are sweet’
So, your Repair log looks like this:

After a few days of tracking the repairs, you wanted to know if same machines are failing successively. For example, in above picture, you notice that MACH-0038 failed twice in a row starting with 11th of March. Same goes for few other rows.
You are the kind of person who frowns upon manually highlighting yellow color in cells to flag such successive failures. So you want to write a formula.
So you add a new column called Same? and want to fill it up with a simple relative reference formula to check with Machine in row 1 matches machine in row 2.
Here is the formula you used:
=[@[Machine ID]] = B6
Note: Your table starts with Row 5.
Excel automatically filled down the formula for all rows of the table, because tables are awesome like that.

You whistled your way to home that night.
Next day morning, as usual Homer messed up something and you had a new repair to log. So you went to the bottom of fail table and inserted a new row to add the failure details.
And you notice something unusual.

The formula for Same? column is WRONG!!!
As soon as you inserted a new row, Excel adjusted last row’s formula to something silly.
- Before: Let’s say the last row formula reads =[@[Machine ID]]=B20
- After: The last but one row (as you now have an empty row)’s formula reads =[@[Machine ID]]=B21
Now that is clearly wrong!
What is going on here?
Your relative referencing worked ok, until the last row. At this stage, Excel understood the formula as Current row value = value in first cell below table
The part in green is what caused trouble. As soon as you add a new row to your table, fist cell below table is moved down. So Excel adjusted that reference alone.
How to fix this problem?
The usual method to fix this:
- Insert as many rows as you need and complete entering / pasting all data.
- Select the formula in very first cell.
- Fill it down all the way (you can double click on the bottom right corner of the cell)
But that is soooo not awesome.
You are right. This method is manual and error prone. It is the opposite of awesome.
Problems when you delete too: In fact, if you ever delete a row from your table, the formulas further down would show #REF! errors. So this method is not very effective in real life.
An elegant way to get relative references in tables
Instead of using cell address based references, like B6, if you use pure structured references, then Excel will automatically adjust them as your table grows or shrinks.
But how?
Simple, we can use OFFSET function along with @ references.
To get next machine ID, you can use
=OFFSET([@[Machine ID]],1,0)
So, to check if same machine failed twice in a row, use
=[@[Machine ID]]=OFFSET([@[Machine ID]],1,0)

As this uses no cell references, whenever you add / change / remove table rows, Excel automatically scales the formula.
But I heard OFFSET is volatile / dangerous / RDX / %#$&@#?
Unless your table has a 200k+ rows or you plan to set up 100s of columns like this, don’t bother. for small, day to day tables, there is no change in performance. If you really hate OFFSET, try talking about it during your next therapy session. Jokes aside, you can also use a longer INDEX based formula to get similar result, but that is semi-volatile too.
Here is one such INDEX based formula.
=INDEX([@[Machine ID]]:INDEX([Machine ID],COUNTA([Machine ID])), 2)
It sure is a mouthful. You can shorten it by using a named formula for INDEX([Machine ID],COUNTA([Machine ID])) portion or the whole thing. Again, I wouldn’t recommend the INDEX based approach over OFFSET for smaller data sets. For larger datasets, see if you can fix the problem at source (for example, modifying your SQL to get offset values in a separate column) or using Power Query to mash the data (more on this in a next post).
So there you go, an elegant and simple way to deal with the relative reference problem in tables.
Bonus tip: generating running numbers in tables
You can use this approach to generate running numbers (1,2,3…) in a table column that grow / change / shrink based on your table. This can be very useful in many scenarios.
To get running numbers in a table column, just use:
=ROWS(fail[[#Headers],[Machine ID]]:[@[Machine ID]])-1
The pattern that you can use in any table goes like this:
=ROWS(Table_Name[[#Headers],[Col 1]]:[@[Col 1]])-1
Bonus Bonus tip: If you have running numbers in a column …
You can then change the OFFSET based relative ref to INDEX like below.
=INDEX([Machine ID],[@Running]+1)
This method is 100% non-volatile, but does return #REF! error for the last row. So use it with IFERROR when nesting in other formulas.
Download Example Workbook
Click here to download an example workbook showcasing all these techniques. Use the extra data to paste and test various methods.
How do you write relative refs in tables?
The handful times when I had to use relative refs in a table, I resorted to cell refs (like B6 above). But this created too much headache further down. So I switched to OFFSET / INDEX approaches.
What about you? How do you write relative references in tables? Please share your stories & struggles in the comments section.
Related Reading (no pun)…
If you are relatively free and want some relaxed reading then check out below related reference links.
- An intro to Excel relative references, structured references
- INDEX formula, OFFSET formula, ROWS formula
Happy learning.














17 Responses to “Custom Number Formats – Colors”
You are right, Chandoo. I was playing with the colour numbers last week and some of them don't appear different from each other. Others are totally different from yours.
@Duncan
Each version of Excel, post 2003, renders colors slightly differently
Different language versions may also have different default color palettes
Hello in french
excel 2010
colo1 = couleur1 = black
[couleur1]; [couleur2]; etc..
@Hui, thank you very much again for this great post.
However - under Excel 2007, Hungarian version your solution does not work with color names. I've tried both English and Hungarian names, but drops an error message "not valid formats"
Do you have any idea how to solve this issue?
thanks in advance
@Andras
Without a Hungarian version of Excel 2003 I don't think I can assist
Have you tried using the colour numbers? I couldn't get the names to work (despite using an english version of excel). but it did work with the numbers though. I left out the "u" and was easily able to produce burgundy using [color9]
Here a possible solution: find an English version of Excel, write there the formats using English names, then open the file in the Hungarian version and see the translation.
In Excel 2007 I can't get the colour names to work e.g Sea Green but the numbers do e.g color3 - colour3 does not work so I must bow to the country that has stolen my language (ha ha!)
Hey chandoo, nice Tip!
Wouldn't be easier just apply some conditional formatting for negative numbers and another for positive numbers? Or there's some cases that you can't do that?
Unfortunately the TEXT function doesn't color the cell as number formatting does.
Hi Hui,
Great post Sir, love the new way of formatting with color numbers.
I am using 2007, and it leads me to the last color number 56.
Thanks Hui.
[…] explains how to set up custom number formats with a wide array of […]
Thanks Hui - works a treat!
Thank you, very helpful.
Trying to figure out if it is possible to apply color only to a part of the cell?
E.g. I have a value formatted as Accounting with a currency symbol.
Those I find somewhat distracting though necessary. If I could make them less obtrusive by coloring them gray while the number would stay black, that would be great. Tried tinkering with the format string, but didn't get the desired result. Single color for complete cell value works, but coloring just part of it could not be achieved. Maybe somebody managed that?
Exactly what I was looking for - thank you!
colour in the Australian doesn't work - we have to go American and no problem.
I always thought is was 56 colours notice you have 57. Cool.
thanks
Analir Pisani
Customised Microsoft Office Training Specialist
Sydney - Australia
http://www.azsolutions.com.au
Thank You!