+ Reply to Thread
Results 1 to 3 of 3

Macro needed to insert blank rows below row based on value in cell in row

Hybrid View

  1. #1
    Registered User
    Join Date
    02-01-2015
    Location
    Kansas City
    MS-Off Ver
    2013
    Posts
    2

    Macro needed to insert blank rows below row based on value in cell in row

    Hello,
    New to forum and each month I need to create an extremely large spreadsheet and need a macro does the following:
    I need a macro that will look the value in B2 and insert the number of rows in cell b2 below the row.

    ColumnA ColumnB ColumnC ColumnD
    Row2 14 xxx yyyy
    Row3 444 aaa bbbb
    Row4 68 zzz rrrrr

    Under Row 2 I need 14 rows inserted, then move to (previously row3, now row15 due to previously inserted 14 rows) and insert 444 rows etc. Once rows are inserted I want to copy the values in Column A, C and D into the number of inserted rows so that it would look like this:

    ColumnA ColumnB ColumnC ColumnD
    Row2 14 xxx yyyy
    Row2 xxx yyyy
    Row2 xxx yyyy
    Row2 xxx yyyy
    Row2 xxx yyyy
    Row2 xxx yyyy
    Row2 xxx yyyy
    Row2 xxx yyyy
    Row2 xxx yyyy
    Row2 xxx yyyy
    Row2 xxx yyyy
    Row2 xxx yyyy
    Row2 xxx yyyy
    Row2 xxx yyyy
    Row2 xxx yyyy
    Row3 444 aaa bbbb
    Row3 aaa bbbb
    Row3 aaa bbbb
    Row3 aaa bbbb
    Row3 aaa bbbb
    Row3 aaa bbbb
    Row3 aaa bbbb
    Row3 aaa bbbb
    Row3 aaa bbbb
    Row3 aaa bbbb


    Hoping someone can help because it will save me about 4 hours of work.
    Thanks so much
    L

  2. #2
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Macro needed to insert blank rows below row based on value in cell in row

    Hi and Welcome.

    Try this

    Sub insertrows()
    Dim rowcount, rownum, insertnum, i As Integer
    rowcount = Application.CountA(Range("A:A")) - 1
    
    rownum = 2
    insertnum = 0
    
    For i = 1 To rowcount + 1
    
    insertnum = Range("b1").Offset(rownum - 1, 0).Value
    
    Rows(rownum + 1 & ":" & rownum + insertnum).Select
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        
    Range("A" & rownum & ":D" & rownum).Select
    Selection.Copy
    Range("A" & rownum & ":A" & rownum + insertnum).Select
    ActiveSheet.Paste
        
    rownum = rownum + insertnum + 1
    
    Next i
    
    End Sub
    Happy with my advice? Click on the * reputation button below

  3. #3
    Registered User
    Join Date
    02-01-2015
    Location
    Kansas City
    MS-Off Ver
    2013
    Posts
    2

    Re: Macro needed to insert blank rows below row based on value in cell in row

    You're my hero! Thank you it worked perfectly.

+ 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. [SOLVED] Excel Macro, VBA help needed - Insert Cell based on value of a cell in another column
    By alw99 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-03-2014, 05:22 PM
  2. [SOLVED] Macro to Insert blank rows based on condition
    By Nikkishr in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-07-2012, 03:32 AM
  3. Insert 2 blank rows and sum columns based on cell value change
    By parreola in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-27-2009, 11:14 PM
  4. insert a blank rows based on cell value
    By pani_hcu in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-28-2009, 09:47 AM
  5. Macro to insert blank rows based on data above
    By MattLinkus in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-22-2007, 06:35 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