LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Declaring a Range Object

Tushar Mehta wrote:

No reason to abandon the Cells property. Just qualify it.


Well, the reason I suggested abandoning it is that the OP said he has
difficulty *remembering* to qualify it, so "just qualify it" is not much
help. And the fact remains that

Set bRng = Worksheets(2).Range("A1")
Set aRng = Range(bRng(1,1),bRng(n,1))

is faster than

With Worksheets(2)
Set aRng = Range(.Cells(1, 1), .Cells(n, 1))
End With

After stumbling onto the then undocumented (as far as I could ascertain)
direct indexing of a range object variable many years ago, I've never
understood why so many people cling to and proliferate the relatively
more cumbersome and inefficient Cells property in lieu of it.

Alan Beban

Sub testIt4()
Dim aRng As Range, n As Integer
n = 7
With Worksheets(2)
Set aRng = Range(.Cells(1, 1), .Cells(n, 1))
End With
MsgBox aRng.Parent.Name & "," & aRng.Address
End Sub

or, if using the equivalent of SHIFT+CTRL+down arrow:

With Worksheets(2).Cells(1, 1)
Set aRng = Range(.Item(1), .End(xlDown))


 
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
Excel Addin:Setting the range to the Excel.Range object range prop Rp007 Excel Worksheet Functions 5 November 24th 06 04:30 PM
Declaring as Object rather than Excel.Worksheet R Avery Excel Programming 3 January 6th 04 11:44 PM
Range object to Array object conversion Myrna Larson[_2_] Excel Programming 1 August 1st 03 02:27 AM
Range object to Array object conversion Alan Beban[_3_] Excel Programming 0 August 1st 03 01:24 AM
Range object to Array object conversion Tom Ogilvy Excel Programming 0 August 1st 03 12:16 AM


All times are GMT +1. The time now is 07:39 PM.

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"