PDA

View Full Version : [SOLVED:] Macro to sum each row if have same value



sidpys
05-13-2012, 06:20 AM
Hello,

First of all sorry for my bad English

I need help to make macro in excel to detect if 2 row in a column have same value then sum value in each row to a new row above and delete 2 original row

For now i doing it manually, but that consume a lot of time because i have a lot of data to process

Herewith i attached some of the file, original sheet is what i get from system and i have to edit manually become target sheet

I truly appreciate any help you can give.
Regards

Sidpys

Bob Phillips
05-13-2012, 09:20 AM
Sub ProcessData()
Dim lastrow As Long
Dim i As Long, ii As Long
With ActiveSheet
lastrow = .Cells(.Rows.Count, "F").End(xlUp).Row
For i = lastrow - 1 To 2 Step -1
If .Cells(i, "A").Value = .Cells(i + 1, "A").Value Then
.Cells(i, "E").Value = .Cells(i, "E").Value + .Cells(i + 1, "E").Value
.Cells(i, "E").NumberFormat = "#,##0"
For ii = 7 To 15
.Cells(i, ii).Value = .Cells(i, ii).Value + .Cells(i + 1, ii).Value
.Cells(i, ii).NumberFormat = "#,##0"
Next ii
.Rows(i + 1).Delete
End If
Next i
lastrow = .Cells(.Rows.Count, "F").End(xlUp).Row
For i = lastrow - 1 To 2 Step -1
If .Cells(i + 1, "F").Value = "Logical stock" Then
.Rows(i + 1).Resize(2).Insert
With .Cells(i + 1, "F").Resize(2)
.Value = Array("Prod. Plan", "M/C No.")
.Font.Bold = True
.Font.ColorIndex = 5
End With
.Cells(i + 3, "G").FormulaR1C1 = "=R[-3]C[-2]-R[-3]C"
.Cells(i + 3, "G").NumberFormat = "#,##0;[red]-#,##0"
For ii = 8 To 15
.Cells(i + 3, ii).FormulaR1C1 = "=RC[-1]-R[-3]C"
.Cells(i + 3, ii).NumberFormat = "#,##0;[red]-#,##0"
Next ii
.Cells(i + 3, "F").Font.Bold = True
End If
Next i
End With
End Sub

sidpys
05-14-2012, 04:39 AM
Hi xld,

First of all thanks for your reply. It is highly appreciated and it has worked like a charm!!

Thank you once again for your help.