Insert blank row and copy row to new blank row

DTMnBHM

New Member
Joined
Dec 27, 2023
Messages
7
Office Version
  1. 365
Platform
  1. Windows
I'm trying to manipulate a spreadsheet with approx 1600 rows of data. I need to insert 1 blank row in between a set or rows, then copy the data above, or below (I'm not sure if when the new row is inserted if it goes above or below the selected rows to copy), into the new blank row. New to the forum and apologize in advance if this has been discussed. I searched and couldn't find my exact need.
 
Hmmm, any chance you can paste a sample of what your data looks like(omitting any personal information information)? Will 1 sheet be needing a row inserted after every row and the other sheet need 2 rows inserted after every row?

In the meantime since you mentioned there are 6 columns with the data, this code

VBA Code:
Sub FillDown()
  With Range("A1:G" & Range("G" & Rows.Count).End(xlUp).Row)
    .SpecialCells(xlBlanks).FormulaR1C1 = "=R[-1]C"
    .Value = .Value
  End With
End Sub

will get you from this:
PERSONAL.xlsm
ABCDEFGH
11deeeee
2
32rdrdrd
4
53fdfdfd
6
74FhFhFh
8
Sheet5


To this:

PERSONAL.xlsm
ABCDEFGH
11deeeee
21deeeee
32rdrdrd
42rdrdrd
53fdfdfd
63fdfdfd
74FhFhFh
8
Sheet5
That looks perfect. And yes, one sheet will need 1 row added between. And the other will need 2
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
That looks perfect. And yes, one sheet will need 1 row added between. And the other will need 2
Got it.

Give this code a try on a sample of your data after you have separated the data into 2 sheets. This code assumes that the worksheets are named Sheet1 and Sheet2 respectively.

VBA Code:
Sub InsertRows()
Dim sht, sh1 As Worksheet
Dim i As Long
Dim LR As Long

Set sht = Worksheets("Sheet1")
Set sh1 = Worksheets("Sheet2")

LR = sht.Range("A" & Rows.Count).End(xlUp).Row

For i = LR To 2 Step -1
    sht.Range("A1:A" & i).EntireRow(i).Insert
    
Next

LR = sh1.Range("A" & Rows.Count).End(xlUp).Row

For i = LR To 2 Step -1
    sh1.Range("A1:A" & i).EntireRow(i).Resize(2).Insert
    
Next

With sht.Range("A1:G" & sht.Range("G" & Rows.Count).End(xlUp).Row)
    .SpecialCells(xlBlanks).FormulaR1C1 = "=R[-1]C"
    .Value = .Value
  End With

With sh1.Range("A1:G" & sh1.Range("G" & Rows.Count).End(xlUp).Row)
    .SpecialCells(xlBlanks).FormulaR1C1 = "=R[-1]C"
    .Value = .Value
  End With
End Sub

This will result in

Sheet1:
PERSONAL.xlsm
ABCDEFG
11ABCDEF
22BCDEFG
33CDEFGH
44DEFGHI
55EFGHIJ
66FGHIJK
77GHIJKL
88HIJKLM
99IJKLMN
1010JKLMNO
Sheet1


PERSONAL.xlsm
ABCDEFG
11ABCDEF
21ABCDEF
32BCDEFG
42BCDEFG
53CDEFGH
63CDEFGH
74DEFGHI
84DEFGHI
95EFGHIJ
105EFGHIJ
116FGHIJK
126FGHIJK
137GHIJKL
147GHIJKL
158HIJKLM
168HIJKLM
179IJKLMN
189IJKLMN
1910JKLMNO
Sheet1



Sheet2:
PERSONAL.xlsm
ABCDEFG
111ABCDEF
212BCDEFG
313CDEFGH
414DEFGHI
515EFGHIJ
616FGHIJK
717GHIJKL
818HIJKLM
919IJKLMN
1020JKLMNO
1121ABCDEF
1222BCDEFG
1323CDEFGH
1424DEFGHI
1525EFGHIJ
1626FGHIJK
1727GHIJKL
1828HIJKLM
1929IJKLMN
2030JKLMNO
2131ABCDEF
2232BCDEFG
2333CDEFGH
2434DEFGHI
2535EFGHIJ
2636FGHIJK
2737GHIJKL
2838HIJKLM
2939IJKLMN
3040JKLMNO
Sheet2


PERSONAL.xlsm
ABCDEFG
111ABCDEF
211ABCDEF
311ABCDEF
412BCDEFG
512BCDEFG
612BCDEFG
713CDEFGH
813CDEFGH
913CDEFGH
1014DEFGHI
1114DEFGHI
1214DEFGHI
1315EFGHIJ
1415EFGHIJ
1515EFGHIJ
1616FGHIJK
1716FGHIJK
1816FGHIJK
1917GHIJKL
2017GHIJKL
2117GHIJKL
2218HIJKLM
2318HIJKLM
2418HIJKLM
2519IJKLMN
2619IJKLMN
2719IJKLMN
2820JKLMNO
2920JKLMNO
3020JKLMNO
3121ABCDEF
3221ABCDEF
3321ABCDEF
3422BCDEFG
3522BCDEFG
3622BCDEFG
3723CDEFGH
3823CDEFGH
3923CDEFGH
4024DEFGHI
4124DEFGHI
4224DEFGHI
4325EFGHIJ
4425EFGHIJ
4525EFGHIJ
4626FGHIJK
4726FGHIJK
4826FGHIJK
4927GHIJKL
5027GHIJKL
5127GHIJKL
5228HIJKLM
5328HIJKLM
5428HIJKLM
5529IJKLMN
5629IJKLMN
5729IJKLMN
5830JKLMNO
5930JKLMNO
6030JKLMNO
6131ABCDEF
6231ABCDEF
6331ABCDEF
6432BCDEFG
6532BCDEFG
6632BCDEFG
6733CDEFGH
6833CDEFGH
6933CDEFGH
7034DEFGHI
7134DEFGHI
7234DEFGHI
7335EFGHIJ
7435EFGHIJ
7535EFGHIJ
7636FGHIJK
7736FGHIJK
7836FGHIJK
7937GHIJKL
8037GHIJKL
8137GHIJKL
8238HIJKLM
8338HIJKLM
8438HIJKLM
8539IJKLMN
8639IJKLMN
8739IJKLMN
8840JKLMNO
Sheet2


Please note that this code is not copying the last row of data. Unsure if you needed to copy that as well. Also, this is not the most efficient code out there as my knowledge is very limited. Depending on how much data you have, it might take a bit to run as inserting rows tend to slow things down in my experience. An alternative way of doing this might be with arrays.

Please let me know if this is a step in the right direction.
 
Upvote 0
It looks like this worked on my small sample. I'm going to run it on the entire data set once I have my sheets correct. Thank you!
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,250
Members
452,623
Latest member
Techenthusiast

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