Excel Macro by Reference :: MrExcel Message Board


 FAQFAQ
   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   FavoritesFavorites   StatisticsStatistics 
 RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Online StoreOnline Store

MrExcel Message Board Forum Index -> Excel Questions

Macro by Reference
Post new topic   Reply to topic
Last Thread | Next Thread  >   Printable version
  Author    Thread

lecxE
Board Regular


Joined: 10 Apr 2002
Posts: 18


Status: Offline

 Reply with quote  

As an example of my dilemma, I simply want a Macro that when executed, copies the contents from the cell immediately above the active cell and moves one cell to the right. I record my macro in cell b2 and I get:

Range("B1").Select
Selection.Copy
Range("B2").Select
ActiveSheet.Paste
Range("C2").Select

Obviously, each time I execute the macro, I copy the same exact data from B1 to B2.

I know I can edit the macro to use ActiveCell.offset, but can I get it to work by reference while recording with keystrokes?

Thanks for any help you may offer.

Post Wed Apr 10, 2002 1:27 pm 
 View user's profile Send private message Send e-mail

AJ
Board Master


Joined: 05 Mar 2002
Posts: 465
Location: =ActiveCell.Address
Flag: Uk

Status: Offline

 Reply with quote  


I'm pretty certain that you cannot do this by recording. Rather only by writing the code.
If you need help with the code, gi's a shout.

Post Wed Apr 10, 2002 1:35 pm 
 View user's profile Send private message

Cosmos75
Board Master


Joined: 01 Mar 2002
Posts: 297
Location: Tulsa, OK

Status: Offline

 Reply with quote  

This should work.

Sub CopyActiveCellAbove()

'Select Cell 1 row above active cell
'which will now be the active cell
ActiveCell.Offset(-1, 0).Select

'Copy Selected Cell
Selection.Copy

'Value of the cell 1 row below new active cell = new active cell
Selection.Offset(1, 0).Value = Selection

'Select cell 1 row down and 1 column to the right of new active cell
ActiveCell.Offset(1, 1).Select

End Sub

EDIT: Added comments to macro so that you can follow what I did.


[ This Message was edited by: cosmos75 on 2002-04-11 10:13 ]

Post Wed Apr 10, 2002 3:03 pm 
 View user's profile Send private message
  Display posts from previous:      

MrExcel Message Board Forum Index -> Excel Questions


Forum Jump:
Jump to:  

Post new topic   Reply to topic
Page 1 of 1



Add To Favorites

 


Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB: 2.0.4 © 2001 phpBB Group

Need help posting your first question? Read how to post

Need extra help ? Couldn't get the answer you needed ? Get a free quote from our Consulting Team

Download Colo's HTML Maker utility for displaying your Excel Worksheet on the board.

Download VB HTML Maker to post your code on the board


Check out our new index to 485 Excel Articles.


Return to MrExcel Consulting

All contents Copyright 1998-2004 by MrExcel.com
If you believe information posted here is from your copyrighted source, notify us per the Terms of Use
Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.