Prova a vedere se così va bene.
Nb: invece di provarla su un range molto esteso provala con pochi records
onde evitare una lunga elaborazione che magari non è ancora come vorresti.
Ho anche cercato di snellirla un po.
Sub elabora()
Application.ScreenUpdating = False
Sheets("foglio1").Select
Dim cl
colonna = 2
r = Range(Cells(1, 1), Cells(1, 1).End(xlDown)).Rows.Count
For h = r To 2 Step -1
If Range("a" & h).Interior.ColorIndex = 7 Then GoTo fine2
x = -1
cl = Range("a" & h).Value
Range("a" & h).Select
riga = -1
y = -1
Do
If h + y = 0 Then Exit Do
If ActiveCell.Offset(y, 0).Interior.ColorIndex () 7 Then
c1 = Mid(cl, 1, 1)
c2 = Mid(cl, 2, 1)
c3 = Mid(cl, 3, 1)
c4 = Mid(cl, 4, 1)
c5 = Mid(cl, 5, 1)
c6 = Mid(cl, 6, 1)
c7 = Mid(cl, 7, 1)
c8 = Mid(cl, 8, 1)
c9 = Mid(cl, 9, 1)
d1 = Mid(ActiveCell.Offset(y, 0), 1, 1)
d2 = Mid(ActiveCell.Offset(y, 0), 2, 1)
d3 = Mid(ActiveCell.Offset(y, 0), 3, 1)
d4 = Mid(ActiveCell.Offset(y, 0), 4, 1)
d5 = Mid(ActiveCell.Offset(y, 0), 5, 1)
d6 = Mid(ActiveCell.Offset(y, 0), 6, 1)
d7 = Mid(ActiveCell.Offset(y, 0), 7, 1)
d8 = Mid(ActiveCell.Offset(y, 0), 8, 1)
d9 = Mid(ActiveCell.Offset(y, 0), 9, 1)
ActiveCell.Offset(0, 1).Select
If d1 - c1 ( 0 Then
ActiveCell.Offset(riga, 0) = (d1 - c1) * x
Else
ActiveCell.Offset(riga, 0) = (d1 - c1)
End If
If d2 - c2 < 0 Then
ActiveCell.Offset(riga, 1) = (d2 - c2) * x
Else
ActiveCell.Offset(riga, 1) = (d2 - c2)
End If
If d3 - c3 < 0 Then
ActiveCell.Offset(riga, 2) = (d3 - c3) * x
Else
ActiveCell.Offset(riga, 2) = (d3 - c3)
End If
If d4 - c4 < 0 Then
ActiveCell.Offset(riga, 3) = (d4 - c4) * x
Else
ActiveCell.Offset(riga, 3) = (d4 - c4)
End If
If d5 - c5 < 0 Then
ActiveCell.Offset(riga, 4) = (d5 - c5) * x
Else
ActiveCell.Offset(riga, 4) = (d5 - c5)
End If
If d6 - c6 < 0 Then
ActiveCell.Offset(riga, 5) = (d6 - c6) * x
Else
ActiveCell.Offset(riga, 5) = (d6 - c6)
End If
If d7 - c7 < 0 Then
ActiveCell.Offset(riga, 6) = (d7 - c7) * x
Else
ActiveCell.Offset(riga, 6) = (d7 - c7)
End If
If d8 - c8 < 0 Then
ActiveCell.Offset(riga, 7) = (d8 - c8) * x
Else
ActiveCell.Offset(riga, 7) = (d8 - c8)
End If
If d9 - c9 < 0 Then
ActiveCell.Offset(riga, 8) = (d9 - c9) * x
Else
ActiveCell.Offset(riga, 8) = (d9 - c9)
End If
Else
ActiveCell.Offset(riga, 1) = 10
ActiveCell.Offset(riga, 2) = 10
ActiveCell.Offset(riga, 3) = 10
ActiveCell.Offset(riga, 4) = 10
ActiveCell.Offset(riga, 5) = 10
ActiveCell.Offset(riga, 6) = 10
ActiveCell.Offset(riga, 7) = 10
ActiveCell.Offset(riga, 8) = 10
ActiveCell.Offset(riga, 9) = 10
End If
Range("a" & h).Select
y = y - 1
riga = riga - 1
Loop
ActiveCell.Select
If h = 2 Then GoTo dopo
Set area3 = Range(Cells(1, 2), Cells(1, 2).End(xlDown))
area3.Select
For Each nr In area3
If nr.Offset(0, -1).Interior.ColorIndex = 7 Then GoTo fine
area3.Select
Set area4 = Range(nr, nr.Offset(0, 8))
area4.Select
If nr <) "" Then
area4.Select
TOTALE = Application.WorksheetFunction.Sum(area4)
nr.Offset(0, 9) = TOTALE
End If
If TOTALE = 2 Then
nr.Offset(0, -1).Interior.ColorIndex = 7
End If
fine:
Next nr
GoTo fine2
dopo:
Set Areas = Range(Cells(1, 2), Cells(1, 2).End(xlToRight))
TOTALE = Application.Sum(Areas)
ActiveCell.Select
ActiveCell.Offset(-1, 10) = TOTALE
If TOTALE = 2 Then
ActiveCell.Interior.ColorIndex = 7
End If
fine2:
Columns("b:k").Select
Selection.ClearContents
Range("a1").Select
Next h
Set area3 = Nothing
Set area4 = Nothing
Application.ScreenUpdating = True
End Sub
saluti
Andrea