PC Review


Reply
Thread Tools Rate Thread

Defining a Range with Cells(r,c)

 
 
Mark Parent
Guest
Posts: n/a
 
      4th Nov 2009
I have a spreadsheet with columns that extend beyond Z. I need to
programmatically select a range, and I opted not to use
COLN = "A"
sheet.range( COLN & "5:" & COLN+3 & "5" ) to avoid issues beyond Z.

I'm using
sheet.range(cells(row,coln),cells(row,coln+3)) which seems to work in most
places.

In this particular case, I need to select and copy / pastespecial cells from
another sheet, and I keep getting error 1004 "Method range". My code is
Set R=Sheets("other").Range(cells(row,coln),cells(row,coln+3)).Copy

Is the issue the use of Cells() within the Range, or the way I'm using the
other sheet?

 
Reply With Quote
 
 
 
 
JBeaucaire
Guest
Posts: n/a
 
      5th Nov 2009
You don't use "Set R = ..." and "....Copy" in the same command.

Just describe the range and end with copy...

Sheets("other").Range(cells(row, coln), cells(row, coln+3)).Copy

--
"Actually, I *am* a rocket scientist." -- JB
(www.MadRocketScientist.com)

Your feedback is appreciated, click YES if this post helped you.


"Mark Parent" wrote:

> I have a spreadsheet with columns that extend beyond Z. I need to
> programmatically select a range, and I opted not to use
> COLN = "A"
> sheet.range( COLN & "5:" & COLN+3 & "5" ) to avoid issues beyond Z.
>
> I'm using
> sheet.range(cells(row,coln),cells(row,coln+3)) which seems to work in most
> places.
>
> In this particular case, I need to select and copy / pastespecial cells from
> another sheet, and I keep getting error 1004 "Method range". My code is
> Set R=Sheets("other").Range(cells(row,coln),cells(row,coln+3)).Copy
>
> Is the issue the use of Cells() within the Range, or the way I'm using the
> other sheet?
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      5th Nov 2009
Watch out for those unqualified ranges:

Sheets("other").Range(cells(row, coln), cells(row, coln+3)).Copy

The cells() will refer to the active sheet (if the code is in a general
module)--and Other may not be that active sheet.

I'd qualify those ranges this way:

with Sheets("other")
.Range(.cells(row, coln), .cells(row, coln+3)).Copy
end with
(the dots mean that those objects belong to the object in the previous With
statement. In this case, Sheets("other").)

Or

Sheets("other").cells(row, coln).resize(1, 4).Copy



JBeaucaire wrote:
>
> You don't use "Set R = ..." and "....Copy" in the same command.
>
> Just describe the range and end with copy...
>
> Sheets("other").Range(cells(row, coln), cells(row, coln+3)).Copy
>
> --
> "Actually, I *am* a rocket scientist." -- JB
> (www.MadRocketScientist.com)
>
> Your feedback is appreciated, click YES if this post helped you.
>
> "Mark Parent" wrote:
>
> > I have a spreadsheet with columns that extend beyond Z. I need to
> > programmatically select a range, and I opted not to use
> > COLN = "A"
> > sheet.range( COLN & "5:" & COLN+3 & "5" ) to avoid issues beyond Z.
> >
> > I'm using
> > sheet.range(cells(row,coln),cells(row,coln+3)) which seems to work in most
> > places.
> >
> > In this particular case, I need to select and copy / pastespecial cells from
> > another sheet, and I keep getting error 1004 "Method range". My code is
> > Set R=Sheets("other").Range(cells(row,coln),cells(row,coln+3)).Copy
> >
> > Is the issue the use of Cells() within the Range, or the way I'm using the
> > other sheet?
> >


--

Dave Peterson
 
Reply With Quote
 
Mark Parent
Guest
Posts: n/a
 
      5th Nov 2009
That's helping... but I'm still stymied...

This statement works, and copies a single cell:
Sheets("other").Cells(7, 4).Copy

But this statement to select a range instead of a single cell fails:


Sheets("other").Range(Cells(8, 4), Cells(40, 5)).Copy

I get a Method 'Range' of object 'Worksheet' failed.
If I can't set a range this way instead of Range("D8:E40"), how can I define
a range beyond column "Z"??


"JBeaucaire" wrote:

> You don't use "Set R = ..." and "....Copy" in the same command.
>
> Just describe the range and end with copy...
>
> Sheets("other").Range(cells(row, coln), cells(row, coln+3)).Copy
>
> --
> "Actually, I *am* a rocket scientist." -- JB
> (www.MadRocketScientist.com)
>
> Your feedback is appreciated, click YES if this post helped you.
>
>
> "Mark Parent" wrote:
>
> > I have a spreadsheet with columns that extend beyond Z. I need to
> > programmatically select a range, and I opted not to use
> > COLN = "A"
> > sheet.range( COLN & "5:" & COLN+3 & "5" ) to avoid issues beyond Z.
> >
> > I'm using
> > sheet.range(cells(row,coln),cells(row,coln+3)) which seems to work in most
> > places.
> >
> > In this particular case, I need to select and copy / pastespecial cells from
> > another sheet, and I keep getting error 1004 "Method range". My code is
> > Set R=Sheets("other").Range(cells(row,coln),cells(row,coln+3)).Copy
> >
> > Is the issue the use of Cells() within the Range, or the way I'm using the
> > other sheet?
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Defining a range as a subset of cells in another range Jay Microsoft Excel Programming 12 23rd Dec 2009 06:38 PM
help with defining column only from range of cells =?Utf-8?B?S0pM?= Microsoft Excel Programming 1 9th Jan 2007 02:05 AM
Defining a range by the contents of cells? travis Microsoft Excel Programming 1 2nd Sep 2006 12:04 PM
Defining Range using Cells T De Villiers Microsoft Excel Programming 8 31st Jul 2006 09:24 AM
defining unique range of cells for different sheets as the same n. =?Utf-8?B?S1NBUFA=?= Microsoft Excel Misc 1 30th Mar 2005 07:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:04 PM.