Insert Row based on above cell value

mccoygs

New Member
Joined
Jun 24, 2019
Messages
1
I want to be able to select the column that I want it to compare the value and if the value changes then insert a row. This code works but it doesn't allow me select the column I want to use and it doesn't stop at the last row that has data it continues to the end of he spreadsheet.

Sub Insert()
Dim LR Ad Long
Application.ScreenUpdating = False
LR = Range("B" & Rows.Count).End9xlUp).Row
Range("B" &LR).Select
Do Until ActiveCell.Row=2
If ActiveCel.Value<> Active.Offset(-1).Value Then
ActieCell.Resze(1).EntireRow.Insert
End If
ActiveCell.Ofse(-1).Select
Loop
Application.ScreenUpdateing - False
End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
This code works

I doubt it with the typo's. Did you copy/paste the code in the thread or retype it?

Anyway try (untested)...

Code:
Sub InsertBlankRows()

    Dim LastRow As Long
    Dim i As Long
    Application.ScreenUpdating = False

    LastRow = Columns(Selection.Column).Find("*", , xlValues, , xlByRows, xlPrevious).Row

    For i = LastRow To 2 Step -1
        If Cells(i, Selection.Column) <> Cells(i - 1, Selection.Column) Then Rows(i).Insert
    Next i

    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,557
Messages
6,114,291
Members
448,564
Latest member
ED38

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