Try this:For row = totalrows To 2 Step -1If Cells(Row, 1).Value = Cells(Row - 1, 1).Value ThenCells(Row-1,3).Value = Cells(Row,2).Value +Cells(Row-1,2).ValueEnd IfNext Row