Hi luajambeiro,
The code below is assuming that there is no blank row in between two cells with value in column-A.
Please try the code below :
(don't forget to remove the "B" bold "/B" attribute)
Sub test()
Set rng1 = Range("A2", Range("A2").End(xlDown))
'create a helper cells to get unique value from column A
rng1.Copy Destination:=Range("Z2")
Set rng2 = Range("Z2", Range("Z2").End(xlDown))
rng2.RemoveDuplicates Columns:=1, Header:=xlNo
'loop through each value of the unique cell
For Each r2Cell In rng2.Cells.SpecialCells(xlCellTypeConstants)
With rng1
.Replace r2Cell.Value, True, xlWhole, , False, , False, False
Set rng3 = .SpecialCells(xlConstants, xlLogical)
Set sum1 = Range(rng3.Offset(0, 4), rng3.Offset(0, 5))
Set sum2 = sum1.Offset(0, 3)
result1 = WorksheetFunction.Sum(sum1)
result2 = WorksheetFunction.Sum(sum2)
If result1 = 0 Then sum1.Cells.SpecialCells(xlCellTypeConstants).Value = ""
If result2 = 0 Then sum2.Cells.SpecialCells(xlCellTypeConstants).Value = ""
.Replace True, r2Cell.Value, xlWhole, , False, , False, False
End With
Next
'clear the cells helper
rng2.ClearContents
End Sub
The line which I bold is a code I just very knew (and learnt) in this week
from one of the senior member here, Fluff13.
Hope it works for you.
Bookmarks