+ Reply to Thread
Results 1 to 10 of 10

Macro to insert a row above the last non blank row

  1. #1
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    Macro to insert a row above the last non blank row

    Hi

    I am using the following macro to copy a row of cells from one sheet to the next blank row on another sheet.
    Is it possible to have the macro do almost the same but insert a row 1 row above the last non blank row?

    "Sub Inv_1_InvList(): Dim w1 As Worksheet, w2 As Worksheet
    Set w1 = Sheets("Inv 1"): Set w2 = Sheets("InvList")
    w1.Range("AG5:EJ5").Copy _
    w2.Range("A" & w2.Range("A" & Rows.Count).End(xlUp).Row + 1)
    End Sub"

    Thansk

  2. #2
    Forum Contributor
    Join Date
    02-09-2009
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    380

    Re: Macro to insert a row above the last non blank row

    Is that code working or is that your attempt to add a row? .Row + 1?

    The reason I ask is that I get most of it apart from that bit. If that is your attempt to add a row try replacing it with .Rows.Insert

  3. #3
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    Re: Macro to insert a row above the last non blank row

    The original code is working fine.
    Last edited by A440; 03-18-2017 at 10:56 AM.

  4. #4
    Forum Contributor
    Join Date
    02-09-2009
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    380

    Re: Macro to insert a row above the last non blank row

    Does this work?
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    Re: Macro to insert a row above the last non blank row

    Sorry no. This adds a row to the first blank row and it inserts a row 2 rows above the row that was the last row before running the macro.

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to insert a row above the last non blank row

    Is this what you want?

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  7. #7
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    Re: Macro to insert a row above the last non blank row

    Hi xladapt,
    No sorry, Your suggestion moves last cell in column A down but not the rest of the row.
    It then pastes the copied row to 2 rows below the moved cell in column A.

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to insert a row above the last non blank row

    Maybe:

    Please Login or Register  to view this content.
    * You could change the red number???

  9. #9
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    Re: Macro to insert a row above the last non blank row

    Hi xladapt, This has inserted the whole row, but still pasted to 2 rows below, so I changed the +2 to -1 and this seems to work.

    "w2.Range("A" & w2.Range("A" & Rows.Count).End(xlUp).Row + 2).PasteSpecial _
    xlPasteValuesAndNumberFormats"

    "w2.Range("A" & w2.Range("A" & Rows.Count).End(xlUp).Row - 1).PasteSpecial _
    xlPasteValuesAndNumberFormats"

    Many thanks for you assistance

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to insert a row above the last non blank row

    You're welcome and thanks for the rep!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How to create a macro to insert blank rows and copy data into blank rows?
    By zodiack101 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-29-2013, 01:18 PM
  2. [SOLVED] Macro to copy row, insert below, invert amt, and insert blank row between each new tx
    By raquel1227 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-07-2013, 12:56 PM
  3. Insert blank row, sum and insert page break macro
    By kim5012 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-06-2012, 01:46 AM
  4. [SOLVED] Macro to insert copy and insert formulas only to next blank row
    By bob in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-30-2006, 07:10 AM
  5. Macro code to test for blank row and insert blank row if false
    By Mattie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-28-2006, 08:25 PM
  6. Macro To Insert Blank Row?
    By rtidrtid in forum Excel General
    Replies: 1
    Last Post: 02-03-2006, 11:10 AM
  7. [SOLVED] Macro to insert blank lines
    By Terry Pinnell in forum Excel General
    Replies: 6
    Last Post: 10-21-2005, 07:05 PM

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