Excel2000: finding last row of used range

A

Arvi Laanemets

Hi

In my procedure I need to determine last used row on worksheet, and I tried
with:
LastRow = Sheets("SheetName").Cells.SpecialCells(xlCellTypeLastCell).Row

At start it looked fine - until I found, that when I p.e. delete some rows
from used range, the SpecialCells(xlCellTypeLastCell) isn't actualized until
I haven't saved my workbook.

The procedure sets the number of premade rows - formated and with formulas
ready for use - to number determined by user. It simply deletes abundant
rows (there is a limit for minimum number of rows left) from bottom of used
range, or adds a number of copies of last row(s).

To save the workbook every time before to reset it can be too
time-consuming. Is there a better way to determine the number of last used
row on worksheet?


Thanks in advance for your help
 
M

Melanie Breden

Hi Arvi,

Arvi said:
In my procedure I need to determine last used row on worksheet, and I tried
with:
LastRow = Sheets("SheetName").Cells.SpecialCells(xlCellTypeLastCell).Row

At start it looked fine - until I found, that when I p.e. delete some rows
from used range, the SpecialCells(xlCellTypeLastCell) isn't actualized until
I haven't saved my workbook.

try this:

LastRow = Sheets("SheetName").Cells.Find("*", searchdirection:=xlPrevious).Row

--
Regards
Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top