Excel Insert Blank Row After Every Two Data Rows #Shorts

If you like this content, please consider visiting the video on YouTube and subscribe to the MrExcel Channel to show your support!
This video has been published on Sep 21, 2022.
LC has 4000 rows of Excel data. After every two rows, he wants to insert a blank row. How can he quickly insert 2000 blank rows in the data? My solution today involves a formula to create alternating cells with text and numbers. Then Home, Find & Select, Go To Special. Select all Formula cells that result in Text. This selects every other row. You can then Insert Sheet Rows and you are done in less than 60 seconds.
maxresdefault.jpg


Transcript of the video:
L.C. has 4000 rows of data.
He needs insert one blank row after every two data rows.
This is going to use Go To Special. Type some text here, a number here.
Equal sign and point to the cell two cells above. Double click the fill handle to shoot that down.
That puts text on every other row. Control G for Go To.
Click Special. Choose Formulas. Unselect Numbers, Logicals, and Errors.
That leaves only the text selected, which gives us every other row.
Home, Insert, Insert Sheet Rows. Let the spinning circle spin for a good 20 - 30 seconds. Don't worry, it's inserting 2000 rows.
And you're done. Clear Column F, press the Delete key.
Great question from LC! Thanks for watching.
Click Subscribe.
 
I thought the following was going to be faster but it takes about the same time.

With VBA in the Immediate window, it can be also accomplished by using the following one liner. The range is supposed to be selected for this implementation.

VBA Code:
For i = Selection.Rows.Count + Int((Selection.Rows.Count \ 2) * 2 = Selection.Rows.Count) To 2 Step -2: Selection.Rows(i).Insert xlDown:Next i
 
A slight variation without the need for formulas (& a couple less clicks in the GoTo dialog)
  1. Leave cell F5 blank
  2. Put a 1 in F6
  3. Select F6 and F7 and double-click the Fill Handle
  4. F5 -> Special.. -> Blanks -> OK
  5. Home, Insert, Insert Sheet Rows.
  6. Clear column F
 
A slight variation without the need for formulas (& a couple less clicks in the GoTo dialog)
  1. Leave cell F5 blank
  2. Put a 1 in F6
  3. Select F6 and F7 and double-click the Fill Handle
  4. F5 -> Special.. -> Blanks -> OK
  5. Home, Insert, Insert Sheet Rows.
  6. Clear column F
Hi Peter - I love this improvement. I managed to get my version down to 17 seconds (see:
)
With your improvements, I can easily shave a few seconds off of that.
 
A slight variation without the need for formulas (& a couple less clicks in the GoTo dialog)
  1. Leave cell F5 blank
  2. Put a 1 in F6
  3. Select F6 and F7 and double-click the Fill Handle
  4. F5 -> Special.. -> Blanks -> OK
  5. Home, Insert, Insert Sheet Rows.
  6. Clear column F
Hi Peter - that makes you the champion right now.... 11.9 seconds. Thanks for these steps.
 
Diarmuid Early pulls it off in 12 seconds:
 
My friend Dan Mayoh sent in an interesting set of steps:
Give the original data the name D.
In G1 =SEQUENCE(6000)
In H1 enter this formula: =IF(MOD(G1#,3)=0,"",INDEX(DATA,ROUNDUP(G1# * 2/3,0),COLUMNS(D)))
copy/paste as values
delete the original data.

This method works great, but I am too slow typing the formula to beat Diarmuid's or Peter's method. However, for someone who wants a formula, this is a good way to go.
 
Here is a Power Query solution from Geert Delmulle:
Power Query:
let
Source = Excel.CurrentWorkbook(){[Name="fInput"]}[Content],
    AddIndex = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type),
RemoveOtherColumns = Table.SelectColumns(AddIndex,{"Index"}),
InsertModulo = Table.AddColumn(RemoveOtherColumns, "Modulo", each Number.Mod([Index], 2), Int64.Type),
    FilterRows = Table.SelectRows(InsertModulo, each ([Modulo] = 0)),
    AppendQuery = Table.Combine({AddIndex, FilterRows}),
SortRows = Table.Sort(AppendQuery,{{"Index", Order.Ascending}}),
RemoveColumns = Table.RemoveColumns(SortRows,{"Index", "Modulo"}),
PromoteHeaders = Table.PromoteHeaders(RemoveColumns, [PromoteAllScalars=true]),
    RemoveTopRow = Table.Skip(PromoteHeaders,1),
ChangeType = Table.TransformColumnTypes(RemoveTopRow,{{"Region", type text}, {"Product", type text}, {"Customer", type text}, {"Date", type date}, {"Revenue", type number}})
in
    ChangeType
 
Here is a Power Query solution from Geert Delmulle:
Power Query:
let
Source = Excel.CurrentWorkbook(){[Name="fInput"]}[Content],
    AddIndex = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type),
RemoveOtherColumns = Table.SelectColumns(AddIndex,{"Index"}),
InsertModulo = Table.AddColumn(RemoveOtherColumns, "Modulo", each Number.Mod([Index], 2), Int64.Type),
    FilterRows = Table.SelectRows(InsertModulo, each ([Modulo] = 0)),
    AppendQuery = Table.Combine({AddIndex, FilterRows}),
SortRows = Table.Sort(AppendQuery,{{"Index", Order.Ascending}}),
RemoveColumns = Table.RemoveColumns(SortRows,{"Index", "Modulo"}),
PromoteHeaders = Table.PromoteHeaders(RemoveColumns, [PromoteAllScalars=true]),
    RemoveTopRow = Table.Skip(PromoteHeaders,1),
ChangeType = Table.TransformColumnTypes(RemoveTopRow,{{"Region", type text}, {"Product", type text}, {"Customer", type text}, {"Date", type date}, {"Revenue", type number}})
in
    ChangeType
That Power Query solution –although fully dynamic– is way too slow! Who wrote that?... Oh wait, that was me! 😉
Here's a fully dynamic array formula:
call the data –er– "data".
Then try this formula in an adjacent cell (don't bother throwing away the original data):
=LET(expanded,WRAPROWS(TOCOL(HSTACK(WRAPROWS(TOCOL(data),10),SEQUENCE(ROWS(data)/2,5,0,0))),5),IF(expanded=0,"",expanded))

If you can type really fast, maybe you can beat the record time.

Hey ExcelLambda, surely you can do better. Give it a shot! :)
 

Forum statistics

Threads
1,223,630
Messages
6,173,457
Members
452,516
Latest member
archcalx

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