Oorang
Well-known Member
- Joined
- Mar 4, 2005
- Messages
- 2,071
There is an art, or rather a knack to finding the last row. The knack lies in learning how to find every used row but the last... And fail.
Code:
Public Sub IFlyNoYouFalled()
MsgBox GetRowsNotLast(ActiveSheet)(1)
End Sub
Public Function GetRowsNotLast(wks As Worksheet) As Long()
Dim cll As Excel.Range
Dim ur1 As Excel.Range
Dim lngRtnVal() As Long
Dim lngIndx As Long
Set ur1 = wks.UsedRange.Columns(1)
ReDim lngRtnVal(1 To ur1.Rows.Count - 1)
For Each cll In ur1.Cells
If cll.Row = ur1.Rows.Count Then
lngIndx = lngIndx + 1
lngRtnVal(lngIndx) = cll.Row + ur1.Row - 1
End If
Next
ReDim Preserve lngRtnVal(1 To lngIndx)
GetRowsNotLast = lngRtnVal()
End Function
Last edited: