Insert blank Rows without formatting

Cowichandave

New Member
Joined
Jan 18, 2009
Messages
44
Office Version
  1. 2016
Here is the code I have so far.
VBA Code:
ActiveCell.EntireRow.Resize(3).Insert Shift:=xlDown
For lRow = Cells(Cells.Rows.Count, "C").End(xlUp).Row To 2 Step -1
        If Cells(lRow, "C") <> Cells(lRow - 1, "C") Then
            Rows(lRow).EntireRow.Insert
            Rows(lRow).EntireRow.Insert
            Rows(lRow).EntireRow.Insert
        End If
    Next lRow

The result is this:
1697496543667.png


I want it to look like below.. Column C is the target for inserting blank rows. I need 3 blank rows without any formatting including conditional formats. Column c may number as high as 40.
1697496613226.png
 
Last edited by a moderator:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hi,

If you are pointing rows, you don't have to use EntireRow:
VBA Code:
  ActiveCell.EntireRow.Resize(3).Insert Shift:=xlDown
  For lRow = Cells(Cells.Rows.Count, "C").End(xlUp).Row To 2 Step -1
    If Cells(lRow, "C") <> Cells(lRow - 1, "C") Then
      Rows(lRow).Insert
      Rows(lRow).Insert
      Rows(lRow).Insert
      Rows(lRow).Resize(3).Clear
    End If
  Next lRow
 
Upvote 0
@Cowichandave
When posting vba code in the forum, please use the available code tags. It makes your code much easier to read/debug & copy. My signature block below has more details. I have added the tags for you this time. 😊
 
Upvote 0
Hi,

If you are pointing rows, you don't have to use EntireRow:
VBA Code:
  ActiveCell.EntireRow.Resize(3).Insert Shift:=xlDown
  For lRow = Cells(Cells.Rows.Count, "C").End(xlUp).Row To 2 Step -1
    If Cells(lRow, "C") <> Cells(lRow - 1, "C") Then
      Rows(lRow).Insert
      Rows(lRow).Insert
      Rows(lRow).Insert
      Rows(lRow).Resize(3).Clear
    End If
  Next lRow
This is inserting 3 blank rows below and 3 blank rows above when it finds a value in Column C. How do I change it to only insert 3 rows above the value in Column C
 
Upvote 0
I don't think I got it quite right. Like this?
VBA Code:
Sub test()
  For Each cll In Range("C2:C" & Cells(Rows.Count, "C").End(xlUp).Row)
    If cll.Value <> "" Then
      cll.EntireRow.Resize(3).Insert
      Rows(cll.Row).Offset(-3).Resize(3).Clear
    End If
  Next
End Sub
 
Upvote 0
Please discard the previous post. Use this instead:
VBA Code:
Sub test()
  Dim lRow As Long, i As Long
  lRow = Cells(Rows.Count, "C").End(xlUp).Row
  For i = lRow To 2 Step -1
    If Cells(i, "C").Value <> "" Then
      Rows(i).Resize(3).Insert
      Rows(i).Resize(3).Clear
    End If
  Next
End Sub
 
Last edited by a moderator:
Upvote 0
Solution
Hi,

If you are pointing rows, you don't have to use EntireRow:
VBA Code:
  ActiveCell.EntireRow.Resize(3).Insert Shift:=xlDown
  For lRow = Cells(Cells.Rows.Count, "C").End(xlUp).Row To 2 Step -1
    If Cells(lRow, "C") <> Cells(lRow - 1, "C") Then
      Rows(lRow).Insert
      Rows(lRow).Insert
      Rows(lRow).Insert
      Rows(lRow).Resize(3).Clear
    End If
  Next lRow

Please discard the previous post. Use this instead:
VBA Code:
Sub test()
  Dim lRow As Long, i As Long
  lRow = Cells(Rows.Count, "C").End(xlUp).Row
  For i = lRow To 2 Step -1
    If Cells(i, "C").Value <> "" Then
      Cells(i, "C").EntireRow.Resize(3).Insert
      Rows(Cells(i, "C").Row).Resize(3).Clear
    End If
  Next
End Sub
That is fabulous. Many thanks. Consider this solved
 
Upvote 0
You are welcome :) Also you can mark the post as answer to help future visitors.
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,975
Members
449,095
Latest member
Mr Hughes

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