My answer focuses on creating a reference to $A$4:A4
that works on all worksheets since that's the part of the reference to which Excel is prepending the unwanted sheet name. (I assume you're not having any trouble referring to the table.)
You can solve this problem using the INDIRECT function as follows:
On any worksheet, select cell A1
Create a named range with a reference of:
=INDIRECT("$A$4"):INDIRECT("R[3]C[0]",FALSE)
Per your question, the second cell in your reference of $A$4:A4
is relative and this name's reference is built accordingly. So if you use this name in cell A1
it will return the range $A$4:A4
. If you reference the name from B1
the name will correctly return a range of $A$4:B4
.
How it Works
The first half of the formula is simple. INDIRECT("$A$4")
will always refer to cell A4
on the current worksheet.
The second half is a bit more complicated. INDIRECT("R[3]C[0]",FALSE)
refers to "3 rows down in the same column, relative to the current cell". If you're in cell A1
this is cell A4
. The FALSE argument tells the INDIRECT function to interpret the text as R1C1-style reference instead of the default A1-style reference.
The Completed Formula
Your final name reference will look something like this:
=COUNTIF(INDIRECT("$A$4"):INDIRECT("R[3]C[0]",FALSE), Tbl_InventoryMain[Barcode])