+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    03-30-2006
    Posts
    7

    OFFSET macro specific col reference

    I want to write a macro which will enable the user, who has selected any row, to insert a new row above the selected row, and copy the data in columns A and B from the row above the inserted row.

    I have:

    Code:
    ActiveCell.EntireRow.Select
    Selection.EntireRow.Insert
    Selection.Offset(-1).Select
          
    Selection.Copy
    Selection.Offset(1).Select
    ActiveSheet.Paste
    This copies the entire previous row. How do I copy only columns A and B, for example? I am sure there is an utterly simple answer but I keep getting syntax or runtime errors with whatever I try.

    Thank you.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    3,714

    Re: OFFSET macro specific col reference

    Perhaps like so, which will insert a row above whichever cell is active:
    Code:
    With ActiveCell
        .Offset(-1).EntireRow.Insert
        Cells(.Row, 1).Resize(, 2).Copy Cells(.Row - 1, 1)
    End With

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0