Excel Formula to find last row

Could someone help me with an excel formula to find the last row in column A even if the data has blanks scattered throughout?

Thanks in advance.

Scott Barnes
ScottBarnesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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:
Formula Solution:

The following formula will return you the row of last cell with data in the range A1:A20
=MAX(INDEX((A1:A20<>"")*ROW(A1:A20),0))

Open in new window


VBA Solution:

The following code will return you the last row with data in col. A
Sub FindLastRowWithData_1()
Dim LR As Long
LR = Cells(Rows.Count, "A").End(xlUp).Row
MsgBox LR
End Sub

Open in new window

Martin LissOlder than dirtCommented:
If you remove the numbers from sktneers' formula it's more flexible.

=MAX(INDEX((A:A<>"")*ROW(A:A),0))

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
ScottBarnesAuthor Commented:
Sorry for not specifying but I need to be able do this using a formula, not vba, it will be used in name manager for a pivot table.  The trick is that the data will sometimes have blanks.  If row 10 is blank and row 11 had data again, I don't want it to return that 9 is the last row.

Currently I'm using this and it doesn't work correctly when there are blanks.

=OFFSET(PivotData!$A$1,0,0,MAX(2,COUNTA(PivotData!$A:$A)),COUNTA(PivotData!$1:$1))

Thank you,
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Martin LissOlder than dirtCommented:
Please see my previous post.
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Try this.....

=OFFSET(PivotData!$A$1,0,0,MAX(INDEX((PivotData!A:A<>"")*ROW(PivotData!A:A),0)),COUNTA(PivotData!$1:$1))

Open in new window

Martin LissOlder than dirtCommented:
@Scott: Please consider Requesting Attention so that you can split the points between sktneer and I since all I did was to modify his formula.
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.