Macro by Reference
Attend Excelapalooza
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Macro by Reference

  1. #1
    Board Regular
    Join Date
    Apr 2002
    Posts
    121
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    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.


  2. #2
    Board Regular
    Join Date
    Mar 2002
    Location
    =ActiveCell.Address
    Posts
    478
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default


    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.

  3. #3
    Board Regular
    Join Date
    Feb 2002
    Location
    Houston, TX
    Posts
    357
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    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 ]

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com