View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Find last used row in named range with data all around

Sub CallTheBottomRowFunction()
Dim lngRow As Long
lngRow = GetBottomRow(ActiveSheet.Range("Hours"))
MsgBox lngRow & " is the last row. "
End Sub

Function GetBottomRow(ByRef TheRange As Excel.Range) As Long
On Error GoTo NoRow
GetBottomRow = TheRange.Cells.Find(what:="*", SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
Exit Function
NoRow:
GetBottomRow = 0
End Function
----------------
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"venus"

wrote in message
Hi,
I'm fairly good with Excel, but new to vba (I barely know what I'm
doing). I have a named range of cells c6:p53, named Hours. There is
data all around this range. I want to find the last used row within
this range and have had no luck.

Almost every solution I've found just gets me the very last row of the
worksheet instead of the range. There is a thread with a solution from
Jim Thomlinson, but I get an "invalid qualifier" error when I use it. I
have looked for days on the net and when I find code that should work,
it doesn't. What's wrong with me and my pc?
Someone, please help me!