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.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Could you not just use Data>Subtotals...?
 
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,446
Members
449,083
Latest member
Ava19

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