+ Reply to Thread
Results 1 to 11 of 11

Insering empty rows after each

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Budapest, Hungary
    MS-Off Ver
    Excel 2016
    Posts
    187

    Insering empty rows after each

    Hello,

    I have a sheet continously populated with rows.
    What I would like to manage is to insert empty lines after each row, so that I have one data-row then one empty row, something like this:
    as is
    data1
    data2
    .
    data n

    to be
    data1
    empty
    data2
    empty
    .
    data n

    The list begins on a fix row, but the number of the rows may vary.
    Can anybody advice, how to manage it?

    Many thanks
    Last edited by HarryKlein; 05-31-2011 at 01:12 AM.

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Insering empty rows after each

    Here is the easiest way.

    In column A (your data is in column B)

    A1 =1
    A2 = 2

    Copy A1:A2 and paste in A3

    Sort by column A smallest to largest

    Now delete column A
    HTH
    Regards, Jeff

  3. #3
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Budapest, Hungary
    MS-Off Ver
    Excel 2016
    Posts
    187

    Re: Insering empty rows after each

    Many thanks,
    but I am afraid, it is ot exactly what I am looking for. I would like to creata a macro, which inserts for me rows after each row while I still have my original list.
    So, finally I would like to have empty lines between the data-rows.

  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Insering empty rows after each

    Why doesn't this method work?

    Please attach a sample workbook detailing exactly what you desire?

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,094

    Re: Insering empty rows after each

    Sub InsertRows()
    
    Dim lLastRow As Long
    Dim i As Long
    lLastRow = Range("A" & Rows.Count).End(xlUp).Row
    
    For i = (lLastRow) To 2 Step -1
        Range("A" & i).EntireRow.Insert
    Next 'i
    
    End Sub

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  6. #6
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Budapest, Hungary
    MS-Off Ver
    Excel 2016
    Posts
    187

    Re: Insering empty rows after each

    Great, this is exactly what I had to do.
    Is there any reason, why you made it from the bottom to the top?

    Thank you

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,094

    Re: Insering empty rows after each

    You're welcome. Thanks for the rep.

    Is there any reason, why you made it from the bottom to the top?
    Oh, yes. Try it and see what happens. ;-)


    Sub InsertRows2()
    
    Dim lLastRow As Long
    Dim i As Long
    lLastRow = Range("A" & Rows.Count).End(xlUp).Row
    
    For i = 2 To lLastRow
        Range("A" & i).EntireRow.Insert
    Next 'i
    
    End Sub

  8. #8
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Inserting empty rows after each

    or
    Sub snb()
      For j = Columns(1).SpecialCells(2).Count To 2 Step -1
        Rows(j).Insert
      Next
    End Sub



  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,094

    Re: Insering empty rows after each

    @snb: I may be a little paranoid, but I'm getting the impression that you're stalking me and reducing my lines of code by 50% ;-) I'll consider it an education ;-))

    Of course, you cheated a little by not Dimming the variable j!

    Regards

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Insering empty rows after each

    @TMShucks

    I have to disappoint you: I'm not.

    And I didn't 'cheat', because that declaration serves no purpose. Because of it's redundancy it can be omitted completely.
    Last edited by snb; 05-31-2011 at 06:38 AM.

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,094

    Re: Insering empty rows after each

    @snb: as you are aware, I have this tendency to use "option explicit" ... an approach with which I know you are not entirely in agreement ... but I would have to define it ;-(

    PS: can't find the thread to which you referred.

+ 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