Need Macro for Insert Row on Unique Value

xbrianx

New Member
Joined
Dec 2, 2010
Messages
24
VoG, I have a macro you supplied in a different thread:

Sub InsRow()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
If Range("A" & i).Value <> Range("A" & i - 1).Value Then Rows(i).Insert
Next i
End Sub


However, this is inserting a row ABOVE and BELOW where the value in column 'A' changes. Can you give me the macro to insert 2 rows ABOVE where the value in column 'A' changes? Thanks.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
To be specific, column 'A' looks like this:

A
(blank)
(blank)
B
(blank)
C
(blank)
(blank)
(blank)
D
(blank)
(blank)
E
(blank)
(blank)
(blank)
(blank)
(blank)
F
(blank)
G
(blank)
(blank)

I have a lot of data in columns in B-N, and I want to but in two blank rows above where there is a NEW value in column 'A'
 
Upvote 0
Still need help with macro to insert row ABOVE unique value

Removing the "-" sign on row4 4 of the macro before the "1" does nothing:

Sub InsRow()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step
-1
If Range("A" & i).Value <> Range("A" & i - 1).Value Then Rows(i).Insert
Next i
End Sub


PLEASE HELP!!!!!!!! Thx.
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

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