PDA

View Full Version : FinalRow



Texasd
02-07-2007, 11:42 AM
Hi All!

I have used

FinalRow = Cells(65536, 1).End(xlUp).row

for months and it works perfectly.

I have a colleague who cannot and receives a run-time error '1004':
Application-defined or object - defined error

Can anyone help?

Please advise.

Thank you,

Donna

malik641
02-07-2007, 11:46 AM
Hey Donna, welcome to VBAX :)

What version of Excel is your colleague using? I'm not familiar with anything older than XL 2000, but the Cells(65536, 1) will return an error if the maximum amount of rows indexed exceeds the actual amount of rows available.

Example, in your application, use Cells(65537, 1) and you'll get the same error.

A better approach is to use Cells(Rows.Count, 1).End(xlUp).Row. I would change that and give it a shot :)

Good luck!!

Bob Phillips
02-07-2007, 11:52 AM
Also, make sure that you qualify it with the worksheet


Dim FinalRow As Long

With Activesheet
FinalRow = .Cells(.Rows.Count,1)>End(xlUp).Row
End With

Texasd
02-07-2007, 12:26 PM
Joseph, that worked perfectly! Thank you very much for the assistance and the welcome. I have found much knowledge on this site and look here for help all the time. Have a great day!

malik641
02-07-2007, 01:11 PM
You're welcome Donna :)

Also, check out xld's post too. It is recommended to explicitly qualify the worksheet you're using.

Take care!

mdmackillop
02-07-2007, 02:12 PM
Here's a function to try for Final Row (http://vbaexpress.com/kb/getarticle.php?kb_id=794)