View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
mp mp is offline
external usenet poster
 
Posts: 70
Default Last used cell in column


"Clif McIrvin" wrote in message
...
"mp" wrote in message
...
Is there a better way to do this?

Function LastRowOfData(oWs As Worksheet, Column As String) As Long
Dim currWs As Worksheet
Set currWs = ActiveSheet

oWs.Activate
Range(Column & "65536").End(xlUp).Select
Dim oCell As Range
Set oCell = ActiveCell
LastRowOfData = oCell.row

currWs.Activate

End Function

it works but looks like a terrible way to find that info to me?

thanks
mark




I've seen others suggest using .End(xlUp) for quickly finding the last
populated cell in a column, so I think that is fine. Your use of .Select
and .Activate is slowing the process down without reason, however. It
took me a long time to realize what was happening; and I don't know if the
explanation is in the help files or not ... but because the macro recorder
is driven off the user interface (i.e., cells and worksheets are getting
selected and activated) that's the way the recorder generates code. This
will run much faster:

Function LastRowOfData(oWs As Worksheet, Column As String) As Long

Set LastRowOfData = oWs.Range(Column & "65536").End(xlUp).Row

End Function

--
Clif McIrvin

(clare reads his mail with moe, nomail feeds the bit bucket :-)


Many thanks.
I felt the select and activate were wrong, but had found a similar usage as
a basis for this function of mine.
wasn't sure how to get rid of them.
Thanks
mark