+ Reply to Thread
Results 1 to 11 of 11

Insert row at the bottom (specific range of columns)

  1. #1
    Registered User
    Join Date
    09-26-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    10

    Insert row at the bottom (specific range of columns)

    Hi,

    I'm trying to write a macro that will add a new row at the bottom of a spreadsheet for a specific range of cells.

    Please take a look at the attached Excel spreadsheet.

    I want to be able to add a new row from column A to E. The new row would need to be added at the bottom, in this case below row 5 and push the row with the "Total" one row below.

    In my current spreadsheet, if you try the macro (CTRL+A), you will notice that the macro adds the new row above the row 5 instead of below.

    Any help would be greatly appreciated.
    Attached Files Attached Files
    Last edited by marcmarina; 09-27-2012 at 10:22 AM. Reason: Typo in title

  2. #2
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Inser row at the bottom (specific range of columns)

    Hello marcmarina,

    I cannot find any Code in your WorkBook to help you with.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  3. #3
    Registered User
    Join Date
    09-26-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Inser row at the bottom (specific range of columns)

    Sorry Wimon. I forgot to save my spreadsheet in macro-enabled format.
    I'm now attaching the correct spreadsheet. Shortcut to run macro is CTRL+SHIFT+A
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    03-09-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Inser row at the bottom (specific range of columns)

    Hello Marina,

    code below:

    "Sub AddRowMacro()
    '
    ' AddRowMacro Macro
    '
    ' Keyboard Shortcut: Ctrl+a
    '

    Range("A1").End(xlDown).Offset(1, 0).Select
    Range(Selection, Selection.Offset(0, 4)).Select
    Selection.Insert Shift:=xlDown
    End Sub"

    just paste that in your module

  5. #5
    Registered User
    Join Date
    03-09-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Inser row at the bottom (specific range of columns)

    hope that helps!
    Last edited by Pavan_Jack; 09-27-2012 at 08:58 AM. Reason: posted twice!

  6. #6
    Valued Forum Contributor
    Join Date
    08-13-2012
    Location
    Gardony, Hungary
    MS-Off Ver
    Excel 2003
    Posts
    558

    Re: Inser row at the bottom (specific range of columns)

    Hi,

    just change the following line in you macro
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    As I see, the "insert" method inserts a row above (not below) the selected range.

    I hope it works at your computer too. :D
    Last edited by RHCPgergo; 09-27-2012 at 09:02 AM.

  7. #7
    Registered User
    Join Date
    09-26-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Inser row at the bottom (specific range of columns)

    Thanks !!
    Is there a way to keep (or apply) the same border style to the new row(s) added. Right now, when adding a new row, it doesn't have the same border style as the other rows.

    Thanks again

  8. #8
    Registered User
    Join Date
    09-26-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Inser row at the bottom (specific range of columns)

    ooops. double post. see previous post.
    Last edited by marcmarina; 09-27-2012 at 09:26 AM.

  9. #9
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Inser row at the bottom (specific range of columns)

    marcmarina,

    Try the attached WorkBook.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    09-26-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Inser row at the bottom (specific range of columns)

    Thanks Winon. I like your solution. Would it be possible to only prompt for the number of rows to add and to add those rows below the “selected” row? Let’s say, I have the cell A5 selected, then I hit “add” and I input “2” rows. The 2 rows would be added in row #6 and #7.

  11. #11
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Inser row at the bottom (specific range of columns)

    Certainly,

    Just replace the Code in the WorkBook with the Code below.

    Please Login or Register  to view this content.
    Last edited by Winon; 09-27-2012 at 11:17 AM.

  12. #12
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Insert row at the bottom (specific range of columns)

    Hello marcmarina,

    I apologise. The Code I have given you does not do exactly what you have asked for.

    See attached WorkBook with corrections which now complies to your request.

    Also see the "Please consider" note at the bottom of this post, and mark your Thread as Solved, if you are satisfied with the solution provided.
    Attached Files Attached Files

+ 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