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

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
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,214,925
Messages
6,122,301
Members
449,078
Latest member
nonnakkong

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