Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Error 1004 when defining range by cells(r,c) format

Whenever I try to define a range with the following
syntax, for example:

Worksheets("Name").Range(Cells(3,3), Cells(2402,3))

I get the following error message:

Run-time error '1004': Application-defined or object-
defined error.

However, defining the range with the following syntax
works just fine:

Worksheets("Name").Range("C3:C2402")

The problem is, I want to be able to treat the row and
column numbers as variables within the code.

The other interesting thing is that the offending method
seems to work once, but then not again, or perhaps only
works if the worksheet happens to be active, which
doesn't help if I'm trying to write to ranges on more
than one worksheet successively.

Can anyone tell me what I'm doing wrong?

Thanks in advance,
Dave Dixon
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Error 1004 when defining range by cells(r,c) format

Dave,

Is sheet 'Name' active when you run this code. If not, it is probably
getting confused as you define the worksheet but then use a Cells reference
on the active sheet. Try

With Worksheets("Name")
.Range(.Cells(3,3), .Cells(2402,3))
etc
End With

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"dave" wrote in message
...
Whenever I try to define a range with the following
syntax, for example:

Worksheets("Name").Range(Cells(3,3), Cells(2402,3))

I get the following error message:

Run-time error '1004': Application-defined or object-
defined error.

However, defining the range with the following syntax
works just fine:

Worksheets("Name").Range("C3:C2402")

The problem is, I want to be able to treat the row and
column numbers as variables within the code.

The other interesting thing is that the offending method
seems to work once, but then not again, or perhaps only
works if the worksheet happens to be active, which
doesn't help if I'm trying to write to ranges on more
than one worksheet successively.

Can anyone tell me what I'm doing wrong?

Thanks in advance,
Dave Dixon



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Error 1004 when defining range by cells(r,c) format

Bob,

Thanks for your reply. Based on your comment that VB was
getting confused about which sheet was open, I was able
to fix the problem by breaking up the code into the
following:

Worksheets("Name").Activate
Range(Cells(x,y), Cells(a,b)).Value = WhatEver

Now it is all working without a hitch. The original code
should still have worked though. By qualifying the Range
property with an Object, I shouldn't have had to do it
this way.

Cheers,
Dave Dixon

-----Original Message-----
Dave,

Is sheet 'Name' active when you run this code. If not,

it is probably
getting confused as you define the worksheet but then

use a Cells reference
on the active sheet. Try

With Worksheets("Name")
.Range(.Cells(3,3), .Cells(2402,3))
etc
End With

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"dave" wrote in message
...
Whenever I try to define a range with the following
syntax, for example:

Worksheets("Name").Range(Cells(3,3), Cells(2402,3))

I get the following error message:

Run-time error '1004': Application-defined or object-
defined error.

However, defining the range with the following syntax
works just fine:

Worksheets("Name").Range("C3:C2402")

The problem is, I want to be able to treat the row and
column numbers as variables within the code.

The other interesting thing is that the offending

method
seems to work once, but then not again, or perhaps only
works if the worksheet happens to be active, which
doesn't help if I'm trying to write to ranges on more
than one worksheet successively.

Can anyone tell me what I'm doing wrong?

Thanks in advance,
Dave Dixon



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Error 1004 when defining range by cells(r,c) format

Dave,

Not if some other worksheet was active as I mentioned.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"dave" wrote in message
...
Bob,

Thanks for your reply. Based on your comment that VB was
getting confused about which sheet was open, I was able
to fix the problem by breaking up the code into the
following:

Worksheets("Name").Activate
Range(Cells(x,y), Cells(a,b)).Value = WhatEver

Now it is all working without a hitch. The original code
should still have worked though. By qualifying the Range
property with an Object, I shouldn't have had to do it
this way.

Cheers,
Dave Dixon

-----Original Message-----
Dave,

Is sheet 'Name' active when you run this code. If not,

it is probably
getting confused as you define the worksheet but then

use a Cells reference
on the active sheet. Try

With Worksheets("Name")
.Range(.Cells(3,3), .Cells(2402,3))
etc
End With

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"dave" wrote in message
...
Whenever I try to define a range with the following
syntax, for example:

Worksheets("Name").Range(Cells(3,3), Cells(2402,3))

I get the following error message:

Run-time error '1004': Application-defined or object-
defined error.

However, defining the range with the following syntax
works just fine:

Worksheets("Name").Range("C3:C2402")

The problem is, I want to be able to treat the row and
column numbers as variables within the code.

The other interesting thing is that the offending

method
seems to work once, but then not again, or perhaps only
works if the worksheet happens to be active, which
doesn't help if I'm trying to write to ranges on more
than one worksheet successively.

Can anyone tell me what I'm doing wrong?

Thanks in advance,
Dave Dixon



.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Error 1004 when defining range by cells(r,c) format



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"dave" wrote in message
...
Bob,

Thanks for your reply. Based on your comment that VB was
getting confused about which sheet was open, I was able
to fix the problem by breaking up the code into the
following:

Worksheets("Name").Activate
Range(Cells(x,y), Cells(a,b)).Value = WhatEver

Now it is all working without a hitch. The original code
should still have worked though. By qualifying the Range
property with an Object, I shouldn't have had to do it
this way.

Cheers,
Dave Dixon

-----Original Message-----
Dave,

Is sheet 'Name' active when you run this code. If not,

it is probably
getting confused as you define the worksheet but then

use a Cells reference
on the active sheet. Try

With Worksheets("Name")
.Range(.Cells(3,3), .Cells(2402,3))
etc
End With

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"dave" wrote in message
...
Whenever I try to define a range with the following
syntax, for example:

Worksheets("Name").Range(Cells(3,3), Cells(2402,3))

I get the following error message:

Run-time error '1004': Application-defined or object-
defined error.

However, defining the range with the following syntax
works just fine:

Worksheets("Name").Range("C3:C2402")

The problem is, I want to be able to treat the row and
column numbers as variables within the code.

The other interesting thing is that the offending

method
seems to work once, but then not again, or perhaps only
works if the worksheet happens to be active, which
doesn't help if I'm trying to write to ranges on more
than one worksheet successively.

Can anyone tell me what I'm doing wrong?

Thanks in advance,
Dave Dixon



.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Error 1004 when defining range by cells(r,c) format

Worksheets("Name").Range(.Cells(3,3), .Cells(2402,3))

Notice the periods - Piku

--
Message posted from http://www.ExcelForum.com

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Error 1004 when defining range by cells(r,c) format

What objects are qualifying those?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"pikus " wrote in message
...
Worksheets("Name").Range(.Cells(3,3), .Cells(2402,3))

Notice the periods - Pikus


---
Message posted from http://www.ExcelForum.com/



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Error 1004 when defining range by cells(r,c) format

In that context .Cells(x, y) is effectively Worksheets
("Name").Cells(x, y). Does that answer your question?

John M.
-----Original Message-----
What objects are qualifying those?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"pikus " wrote in

message
...
Worksheets("Name").Range(.Cells(3,3), .Cells(2402,3))

Notice the periods - Pikus


---
Message posted from http://www.ExcelForum.com/



.

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Error 1004 when defining range by cells(r,c) format

No it doesn't because no it isn't.

My question was pointing out a problem, not seeking enlightenment.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"John M." wrote in message
...
In that context .Cells(x, y) is effectively Worksheets
("Name").Cells(x, y). Does that answer your question?

John M.
-----Original Message-----
What objects are qualifying those?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"pikus " wrote in

message
...
Worksheets("Name").Range(.Cells(3,3), .Cells(2402,3))

Notice the periods - Pikus


---
Message posted from http://www.ExcelForum.com/



.



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
Range.Copy and error 1004 Carl Rapson Excel Programming 5 November 15th 03 03:21 AM
Run-time 1004 error on range select Morgan[_3_] Excel Programming 3 November 11th 03 11:44 PM
Range.cells.calculate give error 1004 only in XP Stef[_3_] Excel Programming 1 October 31st 03 02:57 PM
error 1004 Select method of Range class failed J.E. McGimpsey Excel Programming 1 September 12th 03 07:42 PM
error 1004 - metod Copy of class Range was failed Tom Ogilvy Excel Programming 1 September 10th 03 09:17 AM


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