insert emprty row after every row of data

RAYLWARD102

Well-known Member
Joined
May 27, 2010
Messages
529
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?
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
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
 
Upvote 0
AlphaFrog

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

Thank you
 
Upvote 0
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>
 
Upvote 0
Peter

That works fine thank you very much

My regards to you from a gloomy Southern England
 
Upvote 0
Cheers. By the way, the 'Insert' line doesn't need the Shift:=xlDown
this would be just as good
Code:
Rows(r + 1).Insert
 
Upvote 0

Forum statistics

Threads
1,222,180
Messages
6,164,419
Members
451,894
Latest member
480BOY

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top