Macro to Insert blank row after specified data in a cell

ClaraHam

New Member
Joined
Nov 9, 2017
Messages
7
Currently I have a spreadsheet that was working but isn't anymore. I want the macro to insert a blank row after every instance of a word that starts with "G". Currently, nothing happens. Here is the part of the code:

[TABLE="width: 404"]
<tbody>[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Code:
Dim LR As Long, Rw As Long
    Application.ScreenUpdating = False
    LR = Range("g" & Rows.Count).End(xlUp).Row
    
    For Rw = LR To 2 Step -1
        If Cells(Rw, "G") <> Cells(Rw - 1, "G") Then
            Rows(Rw).Insert xlShiftDown
            
        End If
    Next Rw
    Application.ScreenUpdating = True
    End With

Thank you,
Clara
 
Last edited by a moderator:

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
That code has nothing to with the first letter of a word.
It's simply inserting a new row when the value in Col G changes
 
Upvote 0
Ok well that makes sense, then - but it still isn't working.

Thanks - I will try and work with it. I need a row inserted after every value in column A that is "GL".
 
Upvote 0
Try
Code:
Sub InsertRw()
   Dim i As Long
   For i = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
      If Left(Range("A" & i).Value, 1) = "G" Then Rows(i + 1).Insert
   Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,214
Members
453,024
Latest member
Wingit77

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