insert emprty row after every row of data

RAYLWARD102

Well-known Member
Joined
May 27, 2010
Messages
521
I have a sheet that may have different amounts of data. 1 day it might have 20lines; the next maybe 100. I want a macro that will add 1 empty line below each row of data until the data ends.
example: before code has run

Code:
     A           B            C    
1  mike      test          test
2  bob       test          test
3  trevor    blah          blahbla
 
after macro runs:
 
     A           B            C    
1  mike      test          test
2
3  bob       test          test
4
5  trevor    blah          blahbla
Any idea's?
 

Some videos you may like

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,271
Try something like this...
Code:
Sub Insert_Rows()
    Dim LastRow As Long, r As Long
    
    Application.ScreenUpdating = False
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For r = LastRow To 2 Step -1
        Rows(r).Insert Shift:=xlDown
    Next r
    Application.ScreenUpdating = True
    
End Sub
 

lapta301

Well-known Member
Joined
Nov 12, 2004
Messages
987
Office Version
365
Platform
Windows
AlphaFrog

Is it possible to adjust this slightly to work on a range of selected rows rather than everything?

Thank you
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
45,918
Office Version
365
Platform
Windows
AlphaFrog

Is it possible to adjust this slightly to work on a range of selected rows rather than everything?

Thank you
Try this adaptation.

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> Insert_Rows()<br>    <SPAN style="color:#00007F">Dim</SPAN> LastRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, FirstRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, r <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <br>    Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br>    <SPAN style="color:#00007F">With</SPAN> Selection<br>        FirstRow = .Row<br>        LastRow = FirstRow + .Rows.Count - 1<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <SPAN style="color:#00007F">For</SPAN> r = LastRow <SPAN style="color:#00007F">To</SPAN> FirstRow <SPAN style="color:#00007F">Step</SPAN> -1<br>        Rows(r + 1).Insert Shift:=xlDown<br>    <SPAN style="color:#00007F">Next</SPAN> r<br>    Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br>    <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 

lapta301

Well-known Member
Joined
Nov 12, 2004
Messages
987
Office Version
365
Platform
Windows
Peter

That works fine thank you very much

My regards to you from a gloomy Southern England
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
45,918
Office Version
365
Platform
Windows
Cheers. By the way, the 'Insert' line doesn't need the Shift:=xlDown
this would be just as good
Code:
Rows(r + 1).Insert
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,362
Messages
5,510,855
Members
408,814
Latest member
lgorczyca

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top