refer formula to specific cell

Hi,
I would like to have the below formula modified to refer to a range of cells.
=IF(A9=A8,T8,S9+COUNTIF($A$9:$A$2473,A9)-1)
The above range shows a9:a2473. However the end range can change from sheet to sheet.
row 9 is always the same. The latter part only needs modifying from Countif.....
At the moment the other cell formulas just refer to a cell with 2473 or whatever number of rows there are in the sheet
and I would like to do the same with the above formula rather than having to modify each time.
Any help much appreciated.
Thank You
Ian
ps..... or maybe there is a formula that can refer to the last row of a spreadsheet
Ian BellretiredAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Try this.....

=IF(A9=A8,T8,S9+COUNTIF(INDIRECT("A9:" & "A"&MAX(INDEX(ROW($1:$50000)*($A$1:$A$50000<>""),0))),A9)-1)

Open in new window

The formula assumes 50000 as the max possible row with data in column A. Change it as per your requirement.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DougCommented:
Use the Name Manager to define a commonly named range for each sheet using worksheet scope, setting the range appropriately for each tab. Then reference Tab!Named Range in your formula. You might instead set each data range as a Table and reference the table and header in your formula to replace the cell range in the count if portion.
Ian BellretiredAuthor Commented:
Thanks Sktneer, works perfectly.
Also thanks to Doug but the explanation was way over my head..
I will post another related formula I'd like help with

Thanking You

Ian
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.