Adding rows above rows that contain "NO" in a specific column

ObiWanBaloney

New Member
Joined
May 10, 2012
Messages
23
Hi All,

Here's an example of what I'm trying to do. Here's 3 columns of data:

Yes No Maybe
Yes Yes Maybe
Yes No Maybe
No Maybe Yes

...and so on for ~15000 rows. What I would like to do here is to use VBA to add a blank row above all rows that have "No" in column 2 and only column 2. The end result would look kind of like this:

(new row)
Yes No Maybe
Yes Yes Maybe
(new row)
Yes No Maybe
No Maybe Yes




Thanks!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Code:
Sub addRow()

Dim lRow As Long
Application.ScreenUpdating = False

lRow = Cells(Rows.Count, 2).End(xlUp).Row

    For i = lRow To 1 Step -1
        If Range("B" & i).Offset(1).Value = "No" Then
            Rows(i + 1).Insert
        End If
    Next i
    
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Code:
Sub addRow()

Dim lRow As Long
Application.ScreenUpdating = False

lRow = Cells(Rows.Count, 2).End(xlUp).Row

    For i = lRow To 1 Step -1
        If Range("B" & i).Offset(1).Value = "No" Then
            Rows(i + 1).Insert
        End If
    Next i
    
Application.ScreenUpdating = True
End Sub


Works excellently, thank you! =D
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,972
Members
448,537
Latest member
Et_Cetera

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