Simple VBA to add a row..

Fefur1983

New Member
Joined
Sep 17, 2014
Messages
1
I am trying to find a basic code to automatically insert a new row based on a cell value. I am using Excel 2010. To break it down further, here are the details.
If any cell in the range "W5" to "W50" contains either "SP" or "TS", i want to insert a new blank row directly below whichever row contains either of those 2 statements. If possible, i want the new blank row to maintain the same color, font, etc., formatting as the rest of the page.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Code:
Sub InsertRow()
Dim i As Long
Application.ScreenUpdating = False
With Range("W5:W50")
    For i = .Rows.Count To 1 Step -1
        If .Cells(i).Value = "SP" Or .Cells(i).Value = "TS" Then
            .Cells(i).Offset(1, 0).EntireRow.Insert
        End If
    Next i
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,456
Messages
6,124,939
Members
449,197
Latest member
k_bs

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