Insert Row based on changing data

jslipher

New Member
Joined
Jul 27, 2011
Messages
22
I love visiting these forums and reading all of the responses as I have learned so much from it. Unfortunately I have not been able to find this specific solution in the forum yet. I have a range of data A5:R55 and is sorted by ID's in column B. I would like to automatically insert a row everytime there is a change in ID, but I only want it to do that for the range given since there is more data beneath that range. Also, if there is a way to automatically insert formating such as top/bottom border for that new row would be great as well. Thanks ahead of time for any help you could provide!
 

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).
Try

Code:
Sub InsRow()
Dim I As Long
For I = 55 To 6 Step -1
    With Range("B" & I)
        If .Value <> .Offset(-1).Value Then Rows(I).Insert
    End With
Next I
End Sub
 
Upvote 0
Ok, I actually have one more request that is related to this. After the row has been inserted, I want there to be a subtotal of each column G,H,I,J and then a weighted average of D relative to G for each new inserted row. I realize that the Subtotal tab will automatically do the sum like I'm wanting, but it will not do the weighted average.
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,239
Members
452,898
Latest member
Capolavoro009

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