PC Review


Reply
Thread Tools Rate Thread

Copy range with offset

 
 
Kjeldc
Guest
Posts: n/a
 
      3rd Dec 2009
I know how to copy a cell like this:

..Offset(-1, 13).Select
Selection.Copy
.Offset(0, 13).Select
ActiveSheet.Past-

But how can I copy a range like this


..Offset(-1, 13-21).Select
Selection.Copy
.Offset(0, 13).Select
ActiveSheet.Paste


My programming is self-taught and
my teacher was not very experienced. :-)

cheers,
Kjeld
 
Reply With Quote
 
 
 
 
Kevin Smith
Guest
Posts: n/a
 
      3rd Dec 2009
Hello,

you can do it like

..Offset(-1, 13).range("A1:G1")Select
Selection.Copy
.Offset(0, 13).Select
ActiveSheet.Paste

--
Kevin Smith )


"Kjeldc" wrote:

> I know how to copy a cell like this:
>
> .Offset(-1, 13).Select
> Selection.Copy
> .Offset(0, 13).Select
> ActiveSheet.Past-
>
> But how can I copy a range like this
>
>
> .Offset(-1, 13-21).Select
> Selection.Copy
> .Offset(0, 13).Select
> ActiveSheet.Paste
>
>
> My programming is self-taught and
> my teacher was not very experienced. :-)
>
> cheers,
> Kjeld

 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      3rd Dec 2009
You dont need to select a cell to copy. The below will do

..Offset(-1, 13).Copy .Offset(0, 13)

Similarly... copy to another sheet

Range("A1:C20").Copy Sheets("Sheet2").Range("C1")

--
Jacob


"Kevin Smith" wrote:

> Hello,
>
> you can do it like
>
> .Offset(-1, 13).range("A1:G1")Select
> Selection.Copy
> .Offset(0, 13).Select
> ActiveSheet.Paste
>
> --
> Kevin Smith )
>
>
> "Kjeldc" wrote:
>
> > I know how to copy a cell like this:
> >
> > .Offset(-1, 13).Select
> > Selection.Copy
> > .Offset(0, 13).Select
> > ActiveSheet.Past-
> >
> > But how can I copy a range like this
> >
> >
> > .Offset(-1, 13-21).Select
> > Selection.Copy
> > .Offset(0, 13).Select
> > ActiveSheet.Paste
> >
> >
> > My programming is self-taught and
> > my teacher was not very experienced. :-)
> >
> > cheers,
> > Kjeld

 
Reply With Quote
 
Kjeldc
Guest
Posts: n/a
 
      3rd Dec 2009
Thanks, but I need to copy 9 cells, and now I do it like this:


.Offset(-1, 13).Select
Selection.Copy
.Offset(0, 13).Select
ActiveSheet.Paste

.Offset(-1, 14).Select
Selection.Copy
.Offset(0, 14).Select
ActiveSheet.Paste

.Offset(-1, 15).Select
Selection.Copy
.Offset(0, 15).Select
ActiveSheet.Paste

Is there a better way?

My programming is self-taught and
my teacher was not very experienced. :-)

cheers,
Kjeld


"Jacob Skaria" skrev:

> You dont need to select a cell to copy. The below will do
>
> .Offset(-1, 13).Copy .Offset(0, 13)
>
> Similarly... copy to another sheet
>
> Range("A1:C20").Copy Sheets("Sheet2").Range("C1")
>
> --
> Jacob
>
>
> "Kevin Smith" wrote:
>
> > Hello,
> >
> > you can do it like
> >
> > .Offset(-1, 13).range("A1:G1")Select
> > Selection.Copy
> > .Offset(0, 13).Select
> > ActiveSheet.Paste
> >
> > --
> > Kevin Smith )
> >
> >
> > "Kjeldc" wrote:
> >
> > > I know how to copy a cell like this:
> > >
> > > .Offset(-1, 13).Select
> > > Selection.Copy
> > > .Offset(0, 13).Select
> > > ActiveSheet.Past-
> > >
> > > But how can I copy a range like this
> > >
> > >
> > > .Offset(-1, 13-21).Select
> > > Selection.Copy
> > > .Offset(0, 13).Select
> > > ActiveSheet.Paste
> > >
> > >
> > > My programming is self-taught and
> > > my teacher was not very experienced. :-)
> > >
> > > cheers,
> > > Kjeld

 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      3rd Dec 2009
You havent posted your full code....Are you currently in Active cell. Try the
below

..Offset(-1, 13).Resize(1, 9).Copy .Offset(0, 13)


Jacob


"Kjeldc" wrote:

> Thanks, but I need to copy 9 cells, and now I do it like this:
>
>
> .Offset(-1, 13).Select
> Selection.Copy
> .Offset(0, 13).Select
> ActiveSheet.Paste
>
> .Offset(-1, 14).Select
> Selection.Copy
> .Offset(0, 14).Select
> ActiveSheet.Paste
>
> .Offset(-1, 15).Select
> Selection.Copy
> .Offset(0, 15).Select
> ActiveSheet.Paste
>
> Is there a better way?
>
> My programming is self-taught and
> my teacher was not very experienced. :-)
>
> cheers,
> Kjeld
>
>
> "Jacob Skaria" skrev:
>
> > You dont need to select a cell to copy. The below will do
> >
> > .Offset(-1, 13).Copy .Offset(0, 13)
> >
> > Similarly... copy to another sheet
> >
> > Range("A1:C20").Copy Sheets("Sheet2").Range("C1")
> >
> > --
> > Jacob
> >
> >
> > "Kevin Smith" wrote:
> >
> > > Hello,
> > >
> > > you can do it like
> > >
> > > .Offset(-1, 13).range("A1:G1")Select
> > > Selection.Copy
> > > .Offset(0, 13).Select
> > > ActiveSheet.Paste
> > >
> > > --
> > > Kevin Smith )
> > >
> > >
> > > "Kjeldc" wrote:
> > >
> > > > I know how to copy a cell like this:
> > > >
> > > > .Offset(-1, 13).Select
> > > > Selection.Copy
> > > > .Offset(0, 13).Select
> > > > ActiveSheet.Past-
> > > >
> > > > But how can I copy a range like this
> > > >
> > > >
> > > > .Offset(-1, 13-21).Select
> > > > Selection.Copy
> > > > .Offset(0, 13).Select
> > > > ActiveSheet.Paste
> > > >
> > > >
> > > > My programming is self-taught and
> > > > my teacher was not very experienced. :-)
> > > >
> > > > cheers,
> > > > Kjeld

 
Reply With Quote
 
Kevin Smith
Guest
Posts: n/a
 
      3rd Dec 2009
Hello.

This will copy the cells that you require.
The range A1:G1 starts from the activecell not the actual range A1:G1

..Offset(-1, 13).range("A1:G1")Select
Selection.Copy
.Offset(0, 13).Select
ActiveSheet.Paste
--
Kevin Smith )


"Kjeldc" wrote:

> Thanks, but I need to copy 9 cells, and now I do it like this:
>
>
> .Offset(-1, 13).Select
> Selection.Copy
> .Offset(0, 13).Select
> ActiveSheet.Paste
>
> .Offset(-1, 14).Select
> Selection.Copy
> .Offset(0, 14).Select
> ActiveSheet.Paste
>
> .Offset(-1, 15).Select
> Selection.Copy
> .Offset(0, 15).Select
> ActiveSheet.Paste
>
> Is there a better way?
>
> My programming is self-taught and
> my teacher was not very experienced. :-)
>
> cheers,
> Kjeld
>
>
> "Jacob Skaria" skrev:
>
> > You dont need to select a cell to copy. The below will do
> >
> > .Offset(-1, 13).Copy .Offset(0, 13)
> >
> > Similarly... copy to another sheet
> >
> > Range("A1:C20").Copy Sheets("Sheet2").Range("C1")
> >
> > --
> > Jacob
> >
> >
> > "Kevin Smith" wrote:
> >
> > > Hello,
> > >
> > > you can do it like
> > >
> > > .Offset(-1, 13).range("A1:G1")Select
> > > Selection.Copy
> > > .Offset(0, 13).Select
> > > ActiveSheet.Paste
> > >
> > > --
> > > Kevin Smith )
> > >
> > >
> > > "Kjeldc" wrote:
> > >
> > > > I know how to copy a cell like this:
> > > >
> > > > .Offset(-1, 13).Select
> > > > Selection.Copy
> > > > .Offset(0, 13).Select
> > > > ActiveSheet.Past-
> > > >
> > > > But how can I copy a range like this
> > > >
> > > >
> > > > .Offset(-1, 13-21).Select
> > > > Selection.Copy
> > > > .Offset(0, 13).Select
> > > > ActiveSheet.Paste
> > > >
> > > >
> > > > My programming is self-taught and
> > > > my teacher was not very experienced. :-)
> > > >
> > > > cheers,
> > > > Kjeld

 
Reply With Quote
 
Kjeldc
Guest
Posts: n/a
 
      3rd Dec 2009
Thanks Jacob. I dont understand the "Resize" part, but it seems to do it :-))
--
My programming is self-taught and
my teacher was not very experienced. :-)

cheers,
Kjeld


"Jacob Skaria" skrev:

> You havent posted your full code....Are you currently in Active cell. Try the
> below
>
> .Offset(-1, 13).Resize(1, 9).Copy .Offset(0, 13)
>
>
> Jacob
>
>
> "Kjeldc" wrote:
>
> > Thanks, but I need to copy 9 cells, and now I do it like this:
> >
> >
> > .Offset(-1, 13).Select
> > Selection.Copy
> > .Offset(0, 13).Select
> > ActiveSheet.Paste
> >
> > .Offset(-1, 14).Select
> > Selection.Copy
> > .Offset(0, 14).Select
> > ActiveSheet.Paste
> >
> > .Offset(-1, 15).Select
> > Selection.Copy
> > .Offset(0, 15).Select
> > ActiveSheet.Paste
> >
> > Is there a better way?
> >
> > My programming is self-taught and
> > my teacher was not very experienced. :-)
> >
> > cheers,
> > Kjeld
> >
> >
> > "Jacob Skaria" skrev:
> >
> > > You dont need to select a cell to copy. The below will do
> > >
> > > .Offset(-1, 13).Copy .Offset(0, 13)
> > >
> > > Similarly... copy to another sheet
> > >
> > > Range("A1:C20").Copy Sheets("Sheet2").Range("C1")
> > >
> > > --
> > > Jacob
> > >
> > >
> > > "Kevin Smith" wrote:
> > >
> > > > Hello,
> > > >
> > > > you can do it like
> > > >
> > > > .Offset(-1, 13).range("A1:G1")Select
> > > > Selection.Copy
> > > > .Offset(0, 13).Select
> > > > ActiveSheet.Paste
> > > >
> > > > --
> > > > Kevin Smith )
> > > >
> > > >
> > > > "Kjeldc" wrote:
> > > >
> > > > > I know how to copy a cell like this:
> > > > >
> > > > > .Offset(-1, 13).Select
> > > > > Selection.Copy
> > > > > .Offset(0, 13).Select
> > > > > ActiveSheet.Past-
> > > > >
> > > > > But how can I copy a range like this
> > > > >
> > > > >
> > > > > .Offset(-1, 13-21).Select
> > > > > Selection.Copy
> > > > > .Offset(0, 13).Select
> > > > > ActiveSheet.Paste
> > > > >
> > > > >
> > > > > My programming is self-taught and
> > > > > my teacher was not very experienced. :-)
> > > > >
> > > > > cheers,
> > > > > Kjeld

 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      3rd Dec 2009
Resizes the specified range. Returns a Range object that represents the
resized range.

expression.Resize(RowSize, ColumnSize)

Try
Range("A1").Resize(5, 2).Select

--
Jacob


"Kjeldc" wrote:

> Thanks Jacob. I dont understand the "Resize" part, but it seems to do it :-))
> --
> My programming is self-taught and
> my teacher was not very experienced. :-)
>
> cheers,
> Kjeld
>
>
> "Jacob Skaria" skrev:
>
> > You havent posted your full code....Are you currently in Active cell. Try the
> > below
> >
> > .Offset(-1, 13).Resize(1, 9).Copy .Offset(0, 13)
> >
> >
> > Jacob
> >
> >
> > "Kjeldc" wrote:
> >
> > > Thanks, but I need to copy 9 cells, and now I do it like this:
> > >
> > >
> > > .Offset(-1, 13).Select
> > > Selection.Copy
> > > .Offset(0, 13).Select
> > > ActiveSheet.Paste
> > >
> > > .Offset(-1, 14).Select
> > > Selection.Copy
> > > .Offset(0, 14).Select
> > > ActiveSheet.Paste
> > >
> > > .Offset(-1, 15).Select
> > > Selection.Copy
> > > .Offset(0, 15).Select
> > > ActiveSheet.Paste
> > >
> > > Is there a better way?
> > >
> > > My programming is self-taught and
> > > my teacher was not very experienced. :-)
> > >
> > > cheers,
> > > Kjeld
> > >
> > >
> > > "Jacob Skaria" skrev:
> > >
> > > > You dont need to select a cell to copy. The below will do
> > > >
> > > > .Offset(-1, 13).Copy .Offset(0, 13)
> > > >
> > > > Similarly... copy to another sheet
> > > >
> > > > Range("A1:C20").Copy Sheets("Sheet2").Range("C1")
> > > >
> > > > --
> > > > Jacob
> > > >
> > > >
> > > > "Kevin Smith" wrote:
> > > >
> > > > > Hello,
> > > > >
> > > > > you can do it like
> > > > >
> > > > > .Offset(-1, 13).range("A1:G1")Select
> > > > > Selection.Copy
> > > > > .Offset(0, 13).Select
> > > > > ActiveSheet.Paste
> > > > >
> > > > > --
> > > > > Kevin Smith )
> > > > >
> > > > >
> > > > > "Kjeldc" wrote:
> > > > >
> > > > > > I know how to copy a cell like this:
> > > > > >
> > > > > > .Offset(-1, 13).Select
> > > > > > Selection.Copy
> > > > > > .Offset(0, 13).Select
> > > > > > ActiveSheet.Past-
> > > > > >
> > > > > > But how can I copy a range like this
> > > > > >
> > > > > >
> > > > > > .Offset(-1, 13-21).Select
> > > > > > Selection.Copy
> > > > > > .Offset(0, 13).Select
> > > > > > ActiveSheet.Paste
> > > > > >
> > > > > >
> > > > > > My programming is self-taught and
> > > > > > my teacher was not very experienced. :-)
> > > > > >
> > > > > > cheers,
> > > > > > Kjeld

 
Reply With Quote
 
Kjeldc
Guest
Posts: n/a
 
      3rd Dec 2009
I love it. Saves a lot of code writing :-)
--
My programming is self-taught and
my teacher was not very experienced. :-)

cheers,
Kjeld


"Jacob Skaria" skrev:

> Resizes the specified range. Returns a Range object that represents the
> resized range.
>
> expression.Resize(RowSize, ColumnSize)
>
> Try
> Range("A1").Resize(5, 2).Select
>
> --
> Jacob
>
>
> "Kjeldc" wrote:
>
> > Thanks Jacob. I dont understand the "Resize" part, but it seems to do it :-))
> > --
> > My programming is self-taught and
> > my teacher was not very experienced. :-)
> >
> > cheers,
> > Kjeld
> >
> >
> > "Jacob Skaria" skrev:
> >
> > > You havent posted your full code....Are you currently in Active cell. Try the
> > > below
> > >
> > > .Offset(-1, 13).Resize(1, 9).Copy .Offset(0, 13)
> > >
> > >
> > > Jacob
> > >
> > >
> > > "Kjeldc" wrote:
> > >
> > > > Thanks, but I need to copy 9 cells, and now I do it like this:
> > > >
> > > >
> > > > .Offset(-1, 13).Select
> > > > Selection.Copy
> > > > .Offset(0, 13).Select
> > > > ActiveSheet.Paste
> > > >
> > > > .Offset(-1, 14).Select
> > > > Selection.Copy
> > > > .Offset(0, 14).Select
> > > > ActiveSheet.Paste
> > > >
> > > > .Offset(-1, 15).Select
> > > > Selection.Copy
> > > > .Offset(0, 15).Select
> > > > ActiveSheet.Paste
> > > >
> > > > Is there a better way?
> > > >
> > > > My programming is self-taught and
> > > > my teacher was not very experienced. :-)
> > > >
> > > > cheers,
> > > > Kjeld
> > > >
> > > >
> > > > "Jacob Skaria" skrev:
> > > >
> > > > > You dont need to select a cell to copy. The below will do
> > > > >
> > > > > .Offset(-1, 13).Copy .Offset(0, 13)
> > > > >
> > > > > Similarly... copy to another sheet
> > > > >
> > > > > Range("A1:C20").Copy Sheets("Sheet2").Range("C1")
> > > > >
> > > > > --
> > > > > Jacob
> > > > >
> > > > >
> > > > > "Kevin Smith" wrote:
> > > > >
> > > > > > Hello,
> > > > > >
> > > > > > you can do it like
> > > > > >
> > > > > > .Offset(-1, 13).range("A1:G1")Select
> > > > > > Selection.Copy
> > > > > > .Offset(0, 13).Select
> > > > > > ActiveSheet.Paste
> > > > > >
> > > > > > --
> > > > > > Kevin Smith )
> > > > > >
> > > > > >
> > > > > > "Kjeldc" wrote:
> > > > > >
> > > > > > > I know how to copy a cell like this:
> > > > > > >
> > > > > > > .Offset(-1, 13).Select
> > > > > > > Selection.Copy
> > > > > > > .Offset(0, 13).Select
> > > > > > > ActiveSheet.Past-
> > > > > > >
> > > > > > > But how can I copy a range like this
> > > > > > >
> > > > > > >
> > > > > > > .Offset(-1, 13-21).Select
> > > > > > > Selection.Copy
> > > > > > > .Offset(0, 13).Select
> > > > > > > ActiveSheet.Paste
> > > > > > >
> > > > > > >
> > > > > > > My programming is self-taught and
> > > > > > > my teacher was not very experienced. :-)
> > > > > > >
> > > > > > > cheers,
> > > > > > > Kjeld

 
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
Find, Copy offset to offset on other sheet, Run-time 1004. Finny Microsoft Excel Programming 10 7th Dec 2006 11:46 PM
Copy range using offset range value =?Utf-8?B?Y2Fyb2xpbmU=?= Microsoft Excel Programming 2 16th Feb 2006 02:51 PM
How to apply OFFSET as the range in a basic 'Copy' process... =?Utf-8?B?Y2Rhdmlkc29u?= Microsoft Excel Misc 4 8th Nov 2005 08:43 PM
Problem with Range.Cells.Offset and Range.Cells( row + offset, column) erazmus@actrix.co.nz Microsoft Excel Programming 1 22nd Aug 2005 03:31 AM
Select and Copy Range using Offset jondorv Microsoft Excel Programming 1 16th May 2004 05:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:20 AM.