relative cell references in a formula

Copper Contributor

I have a worksheet that performs a lookup to another sheet to count how many items of the type are there.

 

Anyone familiar with disc golf will recognise what I have in the image below. The only formula is for stock, everything else is static data. For instance cell G2 contains: =COUNTIF(Master!B:B,'Flight Numbers'!B2)   The sheet we're looking at is 'Flight Numbers' and 'Master' contains one line for each item currently in stock.

 

I regularly want to re-order the page using the filter buttons, but when I do, the stock values get mucked up as they stick with the row number they had prior to any re-order.

 

What I'm seeking is a way to structure the formula so that it has some kind of reference to "current column minus 5" - is that possible?

 

DavidHeath_0-1640562184764.png

 

Thanks...

 

6 Replies
Do you have the data in an Excel Table? That only allows entire records to be sorted and a unit and tends to be more meaningful.
I'll take a look. I've heard of tables, but never used them.

Thanks.
Ctrl/L or Ctrl/T are shortcuts to creating a table when a cell within the would be Table is selected. Make sure there is blank space around the table.

@Peter Bartholomew sorry, that didn't work.  I created the table (those alternating stripes are annoying... but, no matter), but when I sorted on a column with the automatically applied filter tool, the cell retained the formula reference for the location it had before the sort, rather than the cell five to the right of its current position.

You can go to the Table Tools tab and deactivate the coloured bands/stripes (yes, it is annoying at times).
After applying the formatted table, re-enter the formula in the first cell of the stock column (you might want to clear the old formula from the enyire column first). Excell will update all the rows with the new formula. Now sorting won't be the problem because you are referring to a data in the same row.
Another note: while creating the formatted table, select the entire data manually including the headers. When given an option, select 'my table has headers' option and continue.
Alternately: To solve the reference, you can make use of INDIRECT function. From what I understand, you don't need it but if nothing works, this might help.

@DavidHeath 

It appears that we have very different work practices, but my best guess as to the formula you require might be as shown in the image

image.png

I have applied your Sheet names to the Tables and used them in preference to references to the Tabs.  As you might observe, I always format Tables to 'White, Table Style Light 1' and deselect Banded Rows.  I would normally deselect Filter Buttons too but that is not what you require.  The criterion value is looked up by column name and the particular value is part of the current record.  The criterion Range is the entire column of the Master Table.

 

This should be robust to any sorting or the insertion of rows or columns, but If it is not what you require then either I or @NowshadAhmed may provide further assistance.