HELP auto insert 2 rows in a spreadsheet

dollfin003

New Member
Joined
Aug 27, 2006
Messages
15
Is it possible to have 2 rows automatically inserted after a name change in a spreadsheet. For example

Abhijeet Pradhan
Aby Abraham Moozikkal-91997
Aditha Suresh Bhatia
AGA Proj/Shameel Pannakar - 15227

so that it would look like this

Abhijeet Pradhan


Aby Abraham Moozikkal-91997


Aditha Suresh Bhatia


AGA Proj/Shameel Pannakar - 15227
 
first try out SUBTOTAL without any other action
then you can tell us if this is close to your needs
(inserting an extra row would not be a problem I think)

I do not understand the amounts in your table
2,443 $83.00 ??
865 $29.35 ??
perhaps you've got more items before?

this is logic in my eyes
129 $4.38

to display tables you would better use a tool
Table-It (see my signature) or colo's htmlmaker (see bottom page)

don't reply to fast
first play a bit with the SUBTOTALS

understand this: the closer you stick to the inbuiltfunctions, the easier you will operate on your sheet
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
The subtotal works perfectly. But this is now what I get. And you are correct I an only shoing you part of the sheet to save space. Here is the real data.

Aditha Suresh Bhatia 07/06/06 11:31AM EDT 1 9 $0.31
Aditha Suresh Bhatia 07/26/06 8:51AM EDT 4 120 $4.07


Aditha Suresh Bhatia Total 0 0 0 0 $0.00


AGA Proj/Shameel Pannakar - 15227 07/03/06 12:25AM EDT 1 1 $0.03
AGA Proj/Shameel Pannakar - 15227 07/03/06 12:25AM EDT 2 4 $0.13
AGA Proj/Shameel Pannakar - 15227 07/03/06 12:29AM EDT 2 3 $0.10
AGA Proj/Shameel Pannakar - 15227 07/03/06 10:33AM EDT 1 22 $0.75
AGA Proj/Shameel Pannakar - 15227 07/27/06 7:29AM EDT 2 51 $1.74


AGA Proj/Shameel Pannakar - 15227 Total 0 0 5 76 $2.59
2,252 $76.47

Ajai Sukumaran Pillai-82940 07/03/06 9:03AM EDT 10 300 $10.20
Ajai Sukumaran Pillai-82940 07/05/06 9:00AM EDT 5 95 $3.23
Ajai Sukumaran Pillai-82940 07/05/06 9:34AM EDT 2 43 $1.46
Ajai Sukumaran Pillai-82940 07/06/06 9:02AM EDT 5 94 $3.19
Ajai Sukumaran Pillai-82940 07/06/06 9:36AM EDT 1 6 $0.20
Ajai Sukumaran Pillai-82940 07/07/06 9:02AM EDT 5 28 $0.96
Ajai Sukumaran Pillai-82940 07/07/06 9:19AM EDT 3 73 $2.48
Ajai Sukumaran Pillai-82940 07/07/06 9:49AM EDT 2 21 $0.71
Ajai Sukumaran Pillai-82940 07/07/06 5:47PM EDT 3 58 $1.97
Ajai Sukumaran Pillai-82940 07/10/06 7:01AM EDT 1 1 $0.03
Ajai Sukumaran Pillai-82940 07/11/06 8:26AM EDT 9 320 $10.88
Ajai Sukumaran Pillai-82940 07/11/06 9:35AM EDT 4 56 $1.90
Ajai Sukumaran Pillai-82940 07/11/06 2:28PM EDT 1 1 $0.03
Ajai Sukumaran Pillai-82940 07/12/06 9:01AM EDT 6 83 $2.82
Ajai Sukumaran Pillai-82940 07/12/06 9:41AM EDT 3 33 $1.12
Ajai Sukumaran Pillai-82940 07/12/06 10:54AM EDT 2 67 $2.28
Ajai Sukumaran Pillai-82940 07/13/06 8:28AM EDT 2 5 $0.17
Ajai Sukumaran Pillai-82940 07/13/06 8:31AM EDT 9 116 $3.94
Ajai Sukumaran Pillai-82940 07/13/06 9:13AM EDT 1 8 $0.27
Ajai Sukumaran Pillai-82940 07/13/06 9:26AM EDT 3 15 $0.51
Ajai Sukumaran Pillai-82940 07/13/06 9:35AM EDT 3 40 $1.36
Ajai Sukumaran Pillai-82940 07/13/06 10:58AM EDT 3 190 $6.45
Ajai Sukumaran Pillai-82940 07/14/06 9:03AM EDT 4 70 $2.39
Ajai Sukumaran Pillai-82940 07/14/06 9:32AM EDT 3 43 $1.47
Ajai Sukumaran Pillai-82940 07/17/06 9:01AM EDT 5 125 $4.25
Ajai Sukumaran Pillai-82940 07/17/06 9:47AM EDT 2 38 $1.30
Ajai Sukumaran Pillai-82940 07/18/06 8:13AM EDT 5 113 $3.84
Ajai Sukumaran Pillai-82940 07/18/06 8:59AM EDT 5 72 $2.45
Ajai Sukumaran Pillai-82940 07/18/06 9:36AM EDT 1 15 $0.51
Ajai Sukumaran Pillai-82940 07/19/06 8:59AM EDT 3 67 $2.29
Ajai Sukumaran Pillai-82940 07/19/06 9:34AM EDT 4 83 $2.82
Ajai Sukumaran Pillai-82940 07/20/06 8:28AM EDT 6 67 $2.27
Ajai Sukumaran Pillai-82940 07/20/06 8:59AM EDT 10 220 $7.47
Ajai Sukumaran Pillai-82940 07/21/06 8:58AM EDT 1 2 $0.07
Ajai Sukumaran Pillai-82940 07/21/06 9:02AM EDT 2 24 $0.82
Ajai Sukumaran Pillai-82940 07/21/06 9:14AM EDT 3 66 $2.24
Ajai Sukumaran Pillai-82940 07/24/06 8:59AM EDT 8 197 $6.69
Ajai Sukumaran Pillai-82940 07/24/06 10:32AM EDT 2 55 $1.87
Ajai Sukumaran Pillai-82940 07/25/06 8:28AM EDT 15 799 $27.17
Ajai Sukumaran Pillai-82940 07/26/06 9:00AM EDT 9 259 $8.81
Ajai Sukumaran Pillai-82940 07/27/06 8:27AM EDT 19 401 $13.64
Ajai Sukumaran Pillai-82940 07/28/06 9:02AM EDT 9 234 $7.96
Ajai Sukumaran Pillai-82940 07/29/06 11:04AM EDT 4 53 $1.80
Ajai Sukumaran Pillai-82940 07/30/06 9:32AM EDT 2 41 $1.39
Ajai Sukumaran Pillai-82940 07/31/06 9:04AM EDT 4 74 $2.51
Ajai Sukumaran Pillai-82940 07/31/06 9:56AM EDT 1 13 $0.44


Ajai Sukumaran Pillai-82940 Total 0 0 195 4,389 $149.20


This is what I really need.

Aditha Suresh Bhatia 07/06/06 11:31AM EDT 1 9 $0.31
Aditha Suresh Bhatia 07/26/06 8:51AM EDT 4 120 $4.07
Aditha Suresh Bhatia Total 5 129 $4.38

AGA Proj/Shameel Pannakar - 15227 07/03/06 12:25AM EDT 1 1 $0.03
AGA Proj/Shameel Pannakar - 15227 07/03/06 12:25AM EDT 2 4 $0.13
AGA Proj/Shameel Pannakar - 15227 07/03/06 12:29AM EDT 2 3 $0.10
AGA Proj/Shameel Pannakar - 15227 07/03/06 10:33AM EDT 1 22 $0.75
AGA Proj/Shameel Pannakar - 15227 07/27/06 7:29AM EDT 2 51 $1.74
AGA Proj/Shameel Pannakar - 15227 Total 5 76 $2.59

Ajai Sukumaran Pillai-82940 07/03/06 9:03AM EDT 10 300 $10.20
Ajai Sukumaran Pillai-82940 07/05/06 9:00AM EDT 5 95 $3.23
Ajai Sukumaran Pillai-82940 07/05/06 9:34AM EDT 2 43 $1.46
Ajai Sukumaran Pillai-82940 07/06/06 9:02AM EDT 5 94 $3.19
Ajai Sukumaran Pillai-82940 07/06/06 9:36AM EDT 1 6 $0.20
Ajai Sukumaran Pillai-82940 07/07/06 9:02AM EDT 5 28 $0.96
Ajai Sukumaran Pillai-82940 07/07/06 9:19AM EDT 3 73 $2.48
Ajai Sukumaran Pillai-82940 07/07/06 9:49AM EDT 2 21 $0.71
Ajai Sukumaran Pillai-82940 07/07/06 5:47PM EDT 3 58 $1.97
Ajai Sukumaran Pillai-82940 07/10/06 7:01AM EDT 1 1 $0.03
Ajai Sukumaran Pillai-82940 07/11/06 8:26AM EDT 9 320 $10.88
Ajai Sukumaran Pillai-82940 07/11/06 9:35AM EDT 4 56 $1.90
Ajai Sukumaran Pillai-82940 07/11/06 2:28PM EDT 1 1 $0.03
Ajai Sukumaran Pillai-82940 07/12/06 9:01AM EDT 6 83 $2.82
Ajai Sukumaran Pillai-82940 07/12/06 9:41AM EDT 3 33 $1.12
Ajai Sukumaran Pillai-82940 07/12/06 10:54AM EDT 2 67 $2.28
Ajai Sukumaran Pillai-82940 07/13/06 8:28AM EDT 2 5 $0.17
Ajai Sukumaran Pillai-82940 07/13/06 8:31AM EDT 9 116 $3.94
Ajai Sukumaran Pillai-82940 07/13/06 9:13AM EDT 1 8 $0.27
Ajai Sukumaran Pillai-82940 07/13/06 9:26AM EDT 3 15 $0.51
Ajai Sukumaran Pillai-82940 07/13/06 9:35AM EDT 3 40 $1.36
Ajai Sukumaran Pillai-82940 07/13/06 10:58AM EDT 3 190 $6.45
Ajai Sukumaran Pillai-82940 07/14/06 9:03AM EDT 4 70 $2.39
Ajai Sukumaran Pillai-82940 07/14/06 9:32AM EDT 3 43 $1.47
Ajai Sukumaran Pillai-82940 07/17/06 9:01AM EDT 5 125 $4.25
Ajai Sukumaran Pillai-82940 07/17/06 9:47AM EDT 2 38 $1.30
Ajai Sukumaran Pillai-82940 07/18/06 8:13AM EDT 5 113 $3.84
Ajai Sukumaran Pillai-82940 07/18/06 8:59AM EDT 5 72 $2.45
Ajai Sukumaran Pillai-82940 07/18/06 9:36AM EDT 1 15 $0.51
Ajai Sukumaran Pillai-82940 07/19/06 8:59AM EDT 3 67 $2.29
Ajai Sukumaran Pillai-82940 07/19/06 9:34AM EDT 4 83 $2.82
Ajai Sukumaran Pillai-82940 07/20/06 8:28AM EDT 6 67 $2.27
Ajai Sukumaran Pillai-82940 07/20/06 8:59AM EDT 10 220 $7.47
Ajai Sukumaran Pillai-82940 07/21/06 8:58AM EDT 1 2 $0.07
Ajai Sukumaran Pillai-82940 07/21/06 9:02AM EDT 2 24 $0.82
Ajai Sukumaran Pillai-82940 07/21/06 9:14AM EDT 3 66 $2.24
Ajai Sukumaran Pillai-82940 07/24/06 8:59AM EDT 8 197 $6.69
Ajai Sukumaran Pillai-82940 07/24/06 10:32AM EDT 2 55 $1.87
Ajai Sukumaran Pillai-82940 07/25/06 8:28AM EDT 15 799 $27.17
Ajai Sukumaran Pillai-82940 07/26/06 9:00AM EDT 9 259 $8.81
Ajai Sukumaran Pillai-82940 07/27/06 8:27AM EDT 19 401 $13.64
Ajai Sukumaran Pillai-82940 07/28/06 9:02AM EDT 9 234 $7.96
Ajai Sukumaran Pillai-82940 07/29/06 11:04AM EDT 4 53 $1.80
Ajai Sukumaran Pillai-82940 07/30/06 9:32AM EDT 2 41 $1.39
Ajai Sukumaran Pillai-82940 07/31/06 9:04AM EDT 4 74 $2.51
Ajai Sukumaran Pillai-82940 07/31/06 9:56AM EDT 1 13 $0.44
Ajai Sukumaran Pillai-82940 Total 195 4,389 $149.20

Ajay Gupta 07/04/06 10:07AM EDT 2 8 $0.27
Ajay Gupta 07/04/06 10:30AM EDT 4 189 $6.42

When I run the subtotal. It works great all data is correct. Then when I run the MACRO you gave me it inserts 2 lines and the gives a running total of the excell spreadsheet at each subtoal.

Aditha Suresh Bhatia 07/06/06 11:31AM EDT 1 9 $0.31
Aditha Suresh Bhatia 07/26/06 8:51AM EDT 4 120 $4.07


Aditha Suresh Bhatia Total 0 0 0 0 $0.00


AGA Proj/Shameel Pannakar - 15227 07/03/06 12:25AM EDT 1 1 $0.03
AGA Proj/Shameel Pannakar - 15227 07/03/06 12:25AM EDT 2 4 $0.13
AGA Proj/Shameel Pannakar - 15227 07/03/06 12:29AM EDT 2 3 $0.10
AGA Proj/Shameel Pannakar - 15227 07/03/06 10:33AM EDT 1 22 $0.75
AGA Proj/Shameel Pannakar - 15227 07/27/06 7:29AM EDT 2 51 $1.74


AGA Proj/Shameel Pannakar - 15227 Total 0 0 5 76 $2.59
2,252 $76.47

Ajai Sukumaran Pillai-82940 07/03/06 9:03AM EDT 10 300 $10.20
Ajai Sukumaran Pillai-82940 07/05/06 9:00AM EDT 5 95 $3.23
Ajai Sukumaran Pillai-82940 07/05/06 9:34AM EDT 2 43 $1.46
Ajai Sukumaran Pillai-82940 07/06/06 9:02AM EDT 5 94 $3.19
Ajai Sukumaran Pillai-82940 07/06/06 9:36AM EDT 1 6 $0.20
Ajai Sukumaran Pillai-82940 07/07/06 9:02AM EDT 5 28 $0.96
Ajai Sukumaran Pillai-82940 07/07/06 9:19AM EDT 3 73 $2.48
Ajai Sukumaran Pillai-82940 07/07/06 9:49AM EDT 2 21 $0.71
Ajai Sukumaran Pillai-82940 07/07/06 5:47PM EDT 3 58 $1.97
Ajai Sukumaran Pillai-82940 07/10/06 7:01AM EDT 1 1 $0.03
Ajai Sukumaran Pillai-82940 07/11/06 8:26AM EDT 9 320 $10.88
Ajai Sukumaran Pillai-82940 07/11/06 9:35AM EDT 4 56 $1.90
Ajai Sukumaran Pillai-82940 07/11/06 2:28PM EDT 1 1 $0.03
Ajai Sukumaran Pillai-82940 07/12/06 9:01AM EDT 6 83 $2.82
Ajai Sukumaran Pillai-82940 07/12/06 9:41AM EDT 3 33 $1.12
Ajai Sukumaran Pillai-82940 07/12/06 10:54AM EDT 2 67 $2.28
Ajai Sukumaran Pillai-82940 07/13/06 8:28AM EDT 2 5 $0.17
Ajai Sukumaran Pillai-82940 07/13/06 8:31AM EDT 9 116 $3.94
Ajai Sukumaran Pillai-82940 07/13/06 9:13AM EDT 1 8 $0.27
Ajai Sukumaran Pillai-82940 07/13/06 9:26AM EDT 3 15 $0.51
Ajai Sukumaran Pillai-82940 07/13/06 9:35AM EDT 3 40 $1.36
Ajai Sukumaran Pillai-82940 07/13/06 10:58AM EDT 3 190 $6.45
Ajai Sukumaran Pillai-82940 07/14/06 9:03AM EDT 4 70 $2.39
Ajai Sukumaran Pillai-82940 07/14/06 9:32AM EDT 3 43 $1.47
Ajai Sukumaran Pillai-82940 07/17/06 9:01AM EDT 5 125 $4.25
Ajai Sukumaran Pillai-82940 07/17/06 9:47AM EDT 2 38 $1.30
Ajai Sukumaran Pillai-82940 07/18/06 8:13AM EDT 5 113 $3.84
Ajai Sukumaran Pillai-82940 07/18/06 8:59AM EDT 5 72 $2.45
Ajai Sukumaran Pillai-82940 07/18/06 9:36AM EDT 1 15 $0.51
Ajai Sukumaran Pillai-82940 07/19/06 8:59AM EDT 3 67 $2.29
Ajai Sukumaran Pillai-82940 07/19/06 9:34AM EDT 4 83 $2.82
Ajai Sukumaran Pillai-82940 07/20/06 8:28AM EDT 6 67 $2.27
Ajai Sukumaran Pillai-82940 07/20/06 8:59AM EDT 10 220 $7.47
Ajai Sukumaran Pillai-82940 07/21/06 8:58AM EDT 1 2 $0.07
Ajai Sukumaran Pillai-82940 07/21/06 9:02AM EDT 2 24 $0.82
Ajai Sukumaran Pillai-82940 07/21/06 9:14AM EDT 3 66 $2.24
Ajai Sukumaran Pillai-82940 07/24/06 8:59AM EDT 8 197 $6.69
Ajai Sukumaran Pillai-82940 07/24/06 10:32AM EDT 2 55 $1.87
Ajai Sukumaran Pillai-82940 07/25/06 8:28AM EDT 15 799 $27.17
Ajai Sukumaran Pillai-82940 07/26/06 9:00AM EDT 9 259 $8.81
Ajai Sukumaran Pillai-82940 07/27/06 8:27AM EDT 19 401 $13.64
Ajai Sukumaran Pillai-82940 07/28/06 9:02AM EDT 9 234 $7.96
Ajai Sukumaran Pillai-82940 07/29/06 11:04AM EDT 4 53 $1.80
Ajai Sukumaran Pillai-82940 07/30/06 9:32AM EDT 2 41 $1.39
Ajai Sukumaran Pillai-82940 07/31/06 9:04AM EDT 4 74 $2.51
Ajai Sukumaran Pillai-82940 07/31/06 9:56AM EDT 1 13 $0.44


Ajai Sukumaran Pillai-82940 Total 0 0 195 4,389 $149.20

So what did i do wrong ???
 
Upvote 0
what is the problem, what is your question now?

I would like to state some conditions to help you further:
1. I recommended you 2 tools to post tables
the way you are posting them needs "5 minutes" to get them on my sheet
so use the tools
2. you don't need to post so much data and so long names: potential helpers need to figure out all those stuff which is not part of the real problem
it's much better to post some "symbolic" data like this
  A       B   
1 person1 10  
2 person1 20  
3 person1 30  
4 person2 100 
5 person2 200 
6 person3 55  
7 person4 10  
8 person4 20  
9 person4 30  

Blad1

[Table-It] version 05 by Erik Van Geit
+
the expected result

best regards,
Erik
 
Upvote 0
oh and by the way you keep refering to TOOLs there is No TOOLs on the message board and I an not sure what TOOLS you are referring to

Regards, Dollfin003
 
Upvote 0
TOOLS
I explained before
to display tables you would better use a tool
Table-It (see my signature) or colo's htmlmaker (see bottom page)
just click in my signature or follow the link "colo ..." at the bottom of the page

as for the example
check my table: wouldn't that be enough to get the idea ?
it's much easier to work with and to understand how things are funtioning
afterwards you can change to your suits

if you really need more colums then feel free to add some, but keep it simple :-)

best regards,
Erik
 
Upvote 0
updated the code

Checks if the number of rows to insert would not be beyond the sheetlimit.
Code:
Option Explicit

Sub insert_rows_on_each_change()
'Erik Van Geit
'080628

'EXAMPLE
'CC = 3, FR = 2, NR = 2
'START WITH
'a1  b1  header  d1
'a2  b2  A   d2
'a3  b3  A   d3
'a4  b4  B   d4
'a5  b5  C   d5
'a6  b6  C   d6
'RESULT
'a1  b1  header  d1
'a2  b2  A   d2
'a3  b3  A   d3
'
'
'a4  b4  B   d4
'
'
'a5  b5  C   d5
'a6  b6  C   d6

Dim rng As Range
Dim LR As Long              'Last Row
Dim CC As Long
Dim FR As Long
Dim NR As Long
Dim NC As Long
Dim cnt As Long

'***** EDIT the following lines ****
CC = 1        'Check this Column
FR = 2        'First Row with data: MINIMUM = 2
NR = 1        'Number of Rows to insert
'NC = 3        'Number of Columns to color
'***** END EDIT ****

Application.ScreenUpdating = False

LR = Cells(Rows.Count, CC).End(xlUp).Row

    With Range(Cells(FR, CC), Cells(LR, CC))
    Set rng = .Resize(.Rows.Count - 1)
    End With
    
    cnt = Evaluate("=SUMPRODUCT(--(" & rng.Address & "<>" & rng.Offset(1).Address & "))")
    
    If LR + cnt > Rows.Count Then
    MsgBox "Impossible to insert all rows!" & vbNewLine & vbNewLine & _
    "Current last row:" & vbTab & LR & vbNewLine & _
    "Rows to insert:" & vbTab & cnt & vbNewLine & _
    "Available rows:" & vbTab & Rows.Count, vbCritical, "ERROR"
    Exit Sub
    End If

Columns(CC).EntireColumn.Insert

Set rng = Range(Cells(FR + 1, CC), Cells(LR, CC))

Cells(FR, CC) = 1

    With rng
    .FormulaR1C1 = "=IF(RC[1]=R[-1]C[1],R[-1]C,R[-1]C+1)"
    .Value = .Value
        With .Offset(.Rows.Count, 0)
        .Cells(1, 1).Value = 1
            With .Resize(.Cells(1, 1).Offset(-1, 0) - 1, 1)
            .DataSeries Rowcol:=xlColumns, Type:=xlLinear, step:=1
                With .Resize(, NC + 1)
                '.Interior.ColorIndex = 15
                .Copy .Resize(NR * .Rows.Count, 1)
                '.RowHeight = 5
                End With
            End With
        End With
    LR = Cells(Rows.Count, CC).End(xlUp).Row
    Range(Cells(FR, CC), Cells(LR, CC)).EntireRow.Sort Key1:=.Cells(1, 1)
    End With

Columns(CC).EntireColumn.Delete

Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,885
Messages
6,181,574
Members
453,055
Latest member
cope7895

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