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:


<tbody>
</tbody>
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

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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,216,090
Messages
6,128,765
Members
449,467
Latest member
sdafasfasdf

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