MACRO help: Insert Rows after each new item in a column

Status
Not open for further replies.

Jillbeirne

New Member
Joined
Sep 17, 2003
Messages
7
hello!

very new to anything besides simple macros, so hopefully some kind-hearted soul will help!

i was wondering how i could create a macro to do the following:

i have a list of advertisers.. i want to insert 2 rows after each change in advertisers; so the macro should compare each row to the one before it, and insert two rows when two cells differ. is that possible? i go to page 15 in reading the other posts, but could not find anything similar!
thanks!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
This assumes that your advertisers names are in column A and there are no blank cells till the end of the list.

Sub SplitAdvertisters()
myRow = 2

Do Until Cells(myRow, 1) = ""

If Cells(myRow, 1) <> Cells(myRow - 1, 1) Then
Rows(myRow).EntireRow.Insert
Rows(myRow).EntireRow.Insert
myRow = myRow + 2
End If
myRow = myRow + 1

Loop

End Sub


HTH

GaryB
 
Upvote 0
My effort - late as usual but...

Sub InsertRows()
Dim r As Long
Dim adv As String
Dim i As Long

r = Cells(Rows.Count, "A").End(xlUp).Row

adv = Cells(r, 1).Value

For i = r To 2 Step -1
If Cells(i, 1).Value = "" Then
adv = Cells(i - 1, 1).Value
Else

If Cells(i, 1).Value <> adv Then
adv = Cells(i, 1).Value
Rows(i + 1).Insert
Rows(i + 1).Insert
End If
End If
Next i

End Sub

If you add extra advertisers directly under your las entry, even after sorting (not leaving a blank row) it will sort these as well.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,216,156
Messages
6,129,192
Members
449,492
Latest member
steveg127

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