LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Range Question / error 1004: method Range of object Worksheet has failed

In a worksheet module, the unqualified use of the term RANGE refers to the
sheet containing the code, so in the Sheet2 code module

Dim ws as Worksheet
set ws = Worksheets("Sheet1")
Set AllCells = Range(ws.Cells(1,1), _
ws.Cells(rows.count,1).End(xlup))

is equivalent to
Dim ws as Worksheet
set ws = Worksheets("Sheet1")
Set AllCells = Worksheets("Sheet2").Range(ws.Cells(1,1), _
ws.Cells(rows.count,1).End(xlup))

Which causes an error since the ranges are on different sheets.

In a general module, the unqualifed Range doesn't appear to have this
restricition.

--
Regards,
Tom Ogilvy


"Paul" <PaulNieboer HEREGOESTHEAD Gmail.com wrote in message
...

Set AllCells = worksheets(1).Range(Worksheets(1).Cells(1, 1), _
Worksheets(1).Cells(65536,1).End(xlUp))

or more concise

with Worksheets(1)
Set AllCells = .Range(.Cells(1, 1), _
.Cells(65536,1).End(xlUp))
End With

--
Regards,
Tom Ogilvy



Cheers Tom,

I would never had thought about putting worksheets in front of, and right
after RANGE. I have been looking quite some time in this newgroups and
others for this answer!!

Now it works like a charm, thanks!!! (btw I now use the With...End With

for
obvious reasons)




 
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
runtime error 1004 method range of object '_global failed valdesd Excel Discussion (Misc queries) 2 October 6th 05 07:26 PM
Runtime Error 1004 - Method Range of '_Global failed' Sworkhard Excel Programming 3 July 9th 04 04:20 AM
Runime Error 1004 Method Range of Object Global Failed Mohan[_5_] Excel Programming 3 May 21st 04 03:35 PM
"Run-time error '1004'" Method 'Range' of object '_global' failed. haisat[_2_] Excel Programming 0 October 20th 03 12:13 PM
error 1004 Select method of Range class failed J.E. McGimpsey Excel Programming 1 September 12th 03 07:42 PM


All times are GMT +1. The time now is 02:01 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"