Macro to insert rows after each grouping

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,509
Office Version
  1. 2021
Platform
  1. Windows
I have data in a spreadsheet and new a row to be inserted after each grouping in col A.

For eg if A1 contains BEE A2 BEE A3 BEE A4 Apples A5 Apples, then I need a row to be inserted after the last item containing BEE, Apples etc in other words I want to seperate the different Groups

See example below of what sheet must look like

your assistance will be most appreciated
spaces+macro (2).xls
ABCD
1bee1
2bee2
3bee3
4
5apple7
6apple8
7apple9
8apple9
9apple9
10apple9
11
12happy9
13happy9
14
15jen9
16
17kite9
18
Sheet1
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Should solve your problem...

Code:
Sub insertrows()
 
    Range("A1").Select
    
    While ActiveCell.Value <> ""
    
        If ActiveCell.Value <> ActiveCell.Offset(1, 0).Value Then
        
            ActiveCell.Offset(1, 0).Select
            ActiveCell.EntireRow.Insert Shift:=xlDown
            
        End If
    
        ActiveCell.Offset(1, 0).Select
        
    Wend
 
End Sub
 
Upvote 0
Hi Sandeep

Thanks for all the help. Much appreciated

Regards

Howard
 
Upvote 0

Forum statistics

Threads
1,203,456
Messages
6,055,543
Members
444,794
Latest member
HSAL

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