Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default selecting a cell relative to activecell in an excel macro

Hi,
I hope some-one can help with this problem:
I am trying to write a macro to do the following:
1) insert a row
2) copy the cell which is right 3 and up 1 from column A in the inserted row
3) paste it to the cell which is down 5 and left 1 from the copied cell
there seems to be a problem with the syntax for the second step:
ActiveCell.Cells(4, -2).Activate
also tried:
ActiveCell.Cells(4, -2).Select
I suspect the problem lies with the negative number used to denote relative movement up, but I have no idea how else to denote this...

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default selecting a cell relative to activecell in an excel macro

Use the offset property to achieve this.
In your example, assuming you have the correct cell
selected:

activecell.offset(5,-1).value=activecell.offset(-1,3).value

OR if you really want to copy the cell rather than just
the value:

activecell.offset(-1,3).copy destination:=activecell.offset
(5,-1)

Cheers, Pete.

-----Original Message-----
Hi,
I hope some-one can help with this problem:
I am trying to write a macro to do the following:
1) insert a row
2) copy the cell which is right 3 and up 1 from column A

in the inserted row
3) paste it to the cell which is down 5 and left 1 from

the copied cell
there seems to be a problem with the syntax for the

second step:
ActiveCell.Cells(4, -2).Activate
also tried:
ActiveCell.Cells(4, -2).Select
I suspect the problem lies with the negative number used

to denote relative movement up, but I have no idea how
else to denote this...

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
Macro relative cell reference decimal Excel Worksheet Functions 3 May 21st 09 11:36 PM
If activecell.column = variable then activecell,offset (0,1) Battykoda via OfficeKB.com Excel Discussion (Misc queries) 1 October 2nd 07 08:05 PM
Macro - getting relative cell addresses to flow down Chris Excel Discussion (Misc queries) 1 August 25th 06 09:27 PM
How do I change a Macro to use relative cell addresses? Roger D Excel Discussion (Misc queries) 1 July 30th 05 07:00 PM
How do i make a macro "relative" to cell? Art Nittskoff Excel Discussion (Misc queries) 4 June 22nd 05 07:05 PM


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