Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default usedrange function

If you want to know the first an last row of the rectangular area that Excel
is maintaining information on (irrespective of wether there are values in
those cells), then yes, I think that should work.

--
Regards,
Tom Ogilvy


"jayy" wrote:


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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default usedrange function


Hi Tom,

Thanks very much for your reply. Out of curiosity, if I did only wan
rows that have text is the best way to loop through each row and chec
for rows that aren't empty?

Thanks.

Ja

--
jay
-----------------------------------------------------------------------
jayy's Profile: http://www.excelforum.com/member.php...fo&userid=3397
View this thread: http://www.excelforum.com/showthread.php?threadid=53856

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default usedrange function

http://www.beyondtechnology.com/geeks012.shtml

--
Regards,
Tom Ogilvy

"jayy" wrote in message
...

Hi Tom,

Thanks very much for your reply. Out of curiosity, if I did only want
rows that have text is the best way to loop through each row and check
for rows that aren't empty?

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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default usedrange function


Hi Tom,

Thanks so much for the info. I really appreciate it!

Jay


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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
RESIZE USEDRANGE ak Excel Programming 2 January 11th 06 10:20 AM
usedRange GC Excel Programming 2 March 31st 05 01:44 PM
usedrange Mike[_94_] Excel Programming 4 February 17th 05 03:59 PM
UsedRange Damien McBain Excel Programming 3 July 4th 04 01:55 PM
Usedrange Terry VanDuzee Excel Programming 6 August 10th 03 05:57 PM


All times are GMT +1. The time now is 03:41 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"