View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
jayy[_3_] jayy[_3_] is offline
external usenet poster
 
Posts: 1
Default usedrange function


I'm just starting to work with functions in VBA. Does something like
this look ok to use when getting the first and last rows of the used
range? I'm wondering if there's a better or more efficient way of
doing this.

-----
Sub test()
a = rangeUsed(0)
b = rangeUsed(1)

MsgBox "first row = " & a & vbLf & "last row = " & b
End Sub


Function rangeUsed()
Dim firstRow As Long, lastRow As Long

With ActiveSheet.UsedRange.Rows
firstRow = .Row
lastRow = .Count + (firstRow - 1)
End With

rangeUsed = Array(firstRow, lastRow)
End Function
-----

Thanks.

Jay


--
jayy
------------------------------------------------------------------------
jayy's Profile: http://www.excelforum.com/member.php...o&userid=33975
View this thread: http://www.excelforum.com/showthread...hreadid=538563