
Sub somma()
Dim area As Range
Dim cl As Range
Dim tot As Single
Set area = ThisWorkbook.Sheets("Foglio1").Range("a1:a600")
area.Offset(0, 5).ClearContents
For Each cl In area
If cl.Value = "" Then Set cl = Nothing: Exit For
If cl.Value = cl.Offset(1, 0).Value Then
If tot = 0 Then
tot = cl.Offset(0, 2).Value + cl.Offset(1, 2).Value
Else
tot = tot + cl.Offset(1, 2).Value
End If
Else
If tot = 0 Then
cl.Offset(0, 5).Value = cl.Offset(0, 2).Value
Else
cl.Offset(0, 5).Value = tot
tot = 0
End If
End If
Next cl
Set area = Nothing
End Sub
|
Sub somma()
Dim area As Range
Dim cl As Range
Dim tot As Single
Set area = ThisWorkbook.Sheets("Foglio1").Range("a2:a600")
area.Offset(1, 11).ClearContents
For Each cl In area
If cl.Value = "" Then Set cl = Nothing: Exit For
If cl.Value = cl.Offset(1, 0).Value Then
If tot = 0 Then
tot = cl.Offset(0, 10).Value + cl.Offset(1, 10).Value
Else
tot = tot + cl.Offset(1, 10).Value
End If
Else
If tot = 0 Then
cl.Offset(0, 11).Value = cl.Offset(0, 2).Value
Else
cl.Offset(0, 11).Value = tot
tot = 0
End If
End If
Next cl
Set area = Nothing
End Sub
|
Sub Somma_2()
Dim Nrig As Long
Dim i As Long
Nrig = Cells(Rows.Count, "A").End(xlUp).Row
On Error Resume Next
Application.EnableEvents = False
Range("L2:L" & Nrig) = ""
For i = 2 To Nrig
If Application.CountIf(Range(Cells(i, "A"), Cells(Nrig, "A")), Cells(i, "A")) = 1 Then
Cells(i, "L") = Application.SumIf(Range("A2:A" & Nrig), Cells(i, "A"), Range("K2:K" & Nrig))
End If
Next i
Application.EnableEvents = True
End Sub |
da cosi'
If Application.CountIf(Range(Cells(i, "A"), Cells(Nrig, "A")), Cells(i, "A")) = 1 Then
Cells(i, "L") = Application.SumIf(Range("A2:A" & Nrig), Cells(i, "A"), Range("K2:K" & Nrig))
End If
a cosi'
If Application.CountIf(Range(Cells(i, "A"), Cells(Nrig, "A")), Cells(i, "A")) = 1 Then
Cells(i, "L") = Application.SumIf(Range("A2:A" & Nrig), Cells(i, "A"), Range("K2:K" & Nrig))
Cells(i, "M") = Format(Cells(i, "A"), "dd/mmm/yy")
End If |
