Insert blank Rows without formatting

Cowichandave

New Member
Joined
Jan 18, 2009
Messages
47
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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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