Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Referencing a Range

I have refered to a range, where I do not know where the end is by
Set rng = Worksheets().Range(Cells(a,b), Cells(c,d)). This tends to be
flaky and I don't want to use the "A1" notation.

Any suggestions?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Referencing a Range

Set rng = Worksheets(1).Range(Cells(a,b), Cells(c,d))

is flakey when worksheets(1) isn't selected.

Cells(a,b) will refer to the activesheet (unless the code is in the worksheet's
sheet module--then it refers to the worksheet that owns the code).

Better to fully qualify the range:

Set rng = Worksheets(1).Range(worksheets(1).Cells(a,b), _
worksheets(1).Cells(c,d))

or with less typing (and fewer things to screw up):

with worksheets(1)
set rng = .range(.cells(a,b), .cells(c,d))
end with

Those dots mean that those ranges refer to the previous with object (in this
case, Worksheets(1).)



Sanj wrote:

I have refered to a range, where I do not know where the end is by
Set rng = Worksheets().Range(Cells(a,b), Cells(c,d)). This tends to be
flaky and I don't want to use the "A1" notation.

Any suggestions?


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Referencing a Range


Where are you giving values to a,b,c,d and why don't you have
worksheet name in Worksheets()

--
Nori
-----------------------------------------------------------------------
Norie's Profile: http://www.excelforum.com/member.php...fo&userid=1936
View this thread: http://www.excelforum.com/showthread.php?threadid=37989

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
Referencing a named range based upon Range name entry in cell Barb Reinhardt Excel Worksheet Functions 14 June 20th 07 07:19 PM
Referencing a Range Sanj Excel Programming 0 June 16th 05 11:13 PM
range referencing lakey13[_6_] Excel Programming 0 November 9th 04 04:30 PM
range referencing lakey13[_4_] Excel Programming 0 November 9th 04 03:38 PM
range referencing lakey13[_3_] Excel Programming 1 November 5th 04 10:46 PM


All times are GMT +1. The time now is 09:52 AM.

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

About Us

"It's about Microsoft Excel"