I'm writing a Macro which loops though the Excel data, which is sorted by column A and inserts a blank row if the the values for coulmn are different from the one above. This separates my data in groups by column A.
I then want to sum the value of column d of the separated groups. I have most of my code working underneath, however its the startCell variable I am having trouble with. I know what I want to do, but cant get the logic right, can someone please help sum up those individual groups.
Sub PutARowInWithFormula() Range("A3").Select Dim startCell As Integer Dim endCell As Integer startCell = 3 endCell = 0 Do Until ActiveCell.Value = "" If ActiveCell.Value = ActiveCell.Offset(-1, 0).Value Then ActiveCell.Offset(1, 0).Select Else ' I need the bottom code to execute only once in the loop ' startCell = ActiveCell.Row ActiveCell.EntireRow.Insert ' move to column d ActiveCell.Offset(0, 3).Select endCell = ActiveCell.Row - 1 ActiveCell.Formula = "=Sum(d" & startCell & ":d" & endCell & ")" ' move back to column a ActiveCell.Offset(0, -3).Select 'move 2 rows down ActiveCell.Offset(3, 0).Select End If Loop End Sub