View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Find the last used Row on a Worksheet

Hope I'm not multiposting today - darn browser keeps hanging

One caveat - the usedrange is not always the last cell that actually has
data in it. For example, if a cell below the last cell w/data has formatting
applied, the formatted cell will be the last cell in the usedrange even
though it is empty.

What could be problematic, is if the usedrange is say D5:F7 (as these are
the only cells that ever had any data in them), your code will select Row 3
(because there are only 3 rows in the usedrange). I think you would need to
change it to:

With ActiveSheet
Set rngLastRow =
..UsedRange.Cells(.UsedRange.Rows.Count,.UsedRange .Columns.Count).EntireRow
End With

but that assumes that the first caveat does not create any problems.



"ilia" wrote:

On Apr 29, 11:35 pm, kirkm
wrote:
Thanks one and all for the help and
code exapmples. Much appreciated & problem solved.
Learnt some valuable stuff too :)
Cheers - Kirk


Dim rngLastRow as Excel.Range

With ActiveSheet
Set rngLastRow
= .Cells(.UsedRange.Rows.Count,.UsedRange.Columns.Co unt).EntireRow
End With