insert a row when data is different & sum up stuff (solv

Samnuni

Board Regular
Joined
Sep 27, 2005
Messages
206
Hi, I have a worksheet with names and numbers. I want to insert a row when the name is different (which I have a macro for) and sum up the numbers for that name right in that blank row. I have post up the macro I found on this site and what I tried to do. Thanks for reading.

Rich (BB code):
Sub AddBlankRow() 
Dim intLastRow As Integer 
Dim i As Integer 
Dim strStartCell As String 
Dim j As Integer
Dim k As Currency

    strStartCell = ActiveCell.Address 
        
    intLastRow = Range("A65536").End(xlUp).Row 
    
    Range("n2").Select 
    k = 0
    j = 1
    For i = 2 To intLastRow 
        If ActiveCell.Value <> ActiveCell.Offset(1, 0).Value Then 
            ActiveCell.Offset(1, 0).Select 
            ActiveCell.EntireRow.Insert (xlDown)
	    Cells(i + j, "P") = "Sum"
	    Cells(i + j, "Q") = ""
	    j = j + 1 
	    k = 0
        End If 
        ActiveCell.Offset(1, 0).Select 
		k = k + 1
    Next i 
    
    Range(strStartCell).Select 
End Sub

The codes in the brackets trying to be bold are what I put in trying to make it work. Basically, I was trying to add up each of the numbers when I skip to the next row then display the sum when I insert a new row.

The names are in column A and the numbers are in column P.
 

Some videos you may like

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,048
Office Version
  1. 365
Platform
  1. Windows
Could you not just use Data>Subtotals...?
 

Watch MrExcel Video

Forum statistics

Threads
1,118,167
Messages
5,570,640
Members
412,334
Latest member
ExcelForLifeDontHate
Top