View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Find last used row in named range with data all around

I'd just loop through the rows--starting at the bottom.

Option Explicit
Sub testme01()

Dim iRow As Long
Dim myRng As Range
Dim LastRow As Long

With Worksheets("Sheet1")
Set myRng = .Range("Hours") 'c6:p53
End With

LastRow = 0
With myRng
For iRow = .Rows.Count To 1 Step -1
If Application.CountA(myRng.Rows(iRow)) = 0 Then
'keep looking
Else
LastRow = .Rows(iRow).Row
Exit For
End If
Next iRow
End With

If LastRow = 0 Then
MsgBox "None used!"
Else
MsgBox "last row was row#: " & LastRow
End If

End Sub



venus wrote:

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!


--

Dave Peterson