Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Inconsistency in how Range object is accepted?

Why is it that this statement is acceptable:

With WorksheetsToFormat(N).Range("A2:G65536")

But this one isn't?

With WorksheetsToFormat(N).Range(Cells(2,1),Cells(65536 ,7))

When I try to use the second one, I get an error that the Range object failed.

WorksheetsToFormat is declared as:
Dim WorksheetsToFormat(1 to 8) as Worksheet
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Inconsistency in how Range object is accepted?

Hi Chris,

This is a case of not fully-qualifying your range references. In your
second example:

With WorksheetsToFormat(N).Range(Cells(2,1),Cells(65536 ,7))


The Cells references are not qualified, so if the worksheet referred to by
WorksheetsToFormat(N) is not the active worksheet (the one used by an
unqualified range reference), you'll get a runtime error. I usually
accomplish this by using a With block, but you're already using one. Maybe
you could nest With blocks like this:

With WorksheetsToFormat(N)
With .Range(.Cells(2,1), .Cells(65536,7))
'/ your code
End With
End With

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Chris B wrote:
Why is it that this statement is acceptable:

With WorksheetsToFormat(N).Range("A2:G65536")

But this one isn't?

With WorksheetsToFormat(N).Range(Cells(2,1),Cells(65536 ,7))

When I try to use the second one, I get an error that the Range
object failed.

WorksheetsToFormat is declared as:
Dim WorksheetsToFormat(1 to 8) as Worksheet


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Inconsistency in how Range object is accepted?

cells must be qualified as well

With WorksheetsToFormat(N)
With .Range(.Cells(2,1),.Cells(65536,7))


End With
End With


or

With WorksheetsToFormat(N).Range("A2").Resize(65535,7)


--
Regards,
Tom Ogilvy


"Chris B" wrote in message
...
Why is it that this statement is acceptable:

With WorksheetsToFormat(N).Range("A2:G65536")

But this one isn't?

With WorksheetsToFormat(N).Range(Cells(2,1),Cells(65536 ,7))

When I try to use the second one, I get an error that the Range object

failed.

WorksheetsToFormat is declared as:
Dim WorksheetsToFormat(1 to 8) as Worksheet



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
Excel inconsistency Robert Baer Excel Discussion (Misc queries) 4 April 17th 09 06:18 PM
returning pivottable object from a range object Grant Excel Programming 2 September 27th 04 02:22 AM
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 12:30 PM.

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"