+ Reply to Thread
Results 1 to 3 of 3

insert row macro - relative to button

Hybrid View

  1. #1
    Registered User
    Join Date
    05-21-2008
    Posts
    1

    insert row macro - relative to button

    I am looking for a bit of help with an insert row macro.

    I need a macro, to be attached to a button, which will insert a new row above the button and copy the formulas down from the row above. The same button will be located in multiple sections of the same sheet.

    If I simply record the macro, it works, but it inserts the new row above which ever cell is highlighted at the time when replayed.

    I can have the actions apply to a named cell using . . .

    Range("INSERT_POINT").Offset(0).EntireRow.Insert

    . . . which works, except, if I want to use this in multiple locations I have to name a lot of cells unique names and have a different macro for each.

    So I guess I am looking for it to perform the macro actions relative to the location of the button itself, not a highlighted cell or named cell.

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,645
    Hi there,

    I think the following code should do what you require. Just assign this macro to the buttons located where you wish to have new rows inserted on your worksheet.

    Sub InsertRow()
    
        ActiveSheet.Shapes(Application.Caller).TopLeftCell.EntireRow.Insert
    
    End Sub
    Hope this helps. Please let me know how you get on.

    Regards,

    Greg M

  3. #3
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    kevlux,

    Welcome to the forum. Please take a few minutes to read the forum rules below and then add the link to the other forum where you have posted this question

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.6.0 RC 1