insert emprty row after every row of data

RAYLWARD102

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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,452
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
1,001
Office Version
  1. 365
Platform
  1. 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
56,593
Office Version
  1. 365
Platform
  1. 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
1,001
Office Version
  1. 365
Platform
  1. 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
56,593
Office Version
  1. 365
Platform
  1. 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
 

Forum statistics

Threads
1,176,401
Messages
5,902,843
Members
435,000
Latest member
jmc12

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
Top