insert blank row if the left(cell,3) is different then one above

johnnyhammer

New Member
Joined
Nov 8, 2015
Messages
7
I need to insert a blank row if the left, 3 does not match. the code below, does not separate correctly.
Code:

Code:
Application.ScreenUpdating = False


Dim iRow As Integer, iCol As Integer
Dim oRng As Range


Set oRng = Worksheets("doc1").Range("A2")


iRow = oRng.Row
iCol = oRng.Column


Do
'
If Cells(Left(iRow + 1, iCol), 3) <> Cells(Left(iRow, iCol), 3) Then
    Cells(iRow + 1, iCol).EntireRow.Insert shift:=xlDown
    iRow = iRow + 2
Else
    iRow = iRow + 1
End If
'
Loop While Not Cells(iRow, iCol).Text = ""


Application.ScreenUpdating = True
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
How about
Code:
Sub johnnyhammer()
   Dim i As Long
   
   With Sheets("doc1")
      For i = .Range("A" & Rows.Count).End(xlUp).Row To 3 Step -1
         If Left(.Cells(i, 1), 3) <> Left(.Cells(i - 1, 1), 3) Then
            .Rows(i).Insert
         End If
      Next i
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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