>>>saranno protette contro la cancellazione.
Intendo che tutta la procedura non termina con l'aggiunta di una sola riga. Vedo pure un =SOMMA() e presumo che ci saranno pure eventuali cancellazioni di righe....
>>>Sono ben accettati i consigli.
1) Hai cambiato totalmente il significato del codice
Non mi sembra una cosa valida, comunque questo gli fai un bottone e lo avvii ogni volta.Non inserisce nessuna riga, fà solo i totali.
Sub conta()
Dim Ur, X, Tot1 As Double, Tot2 As Double
Ur = Range("E" & Rows.Count).End(xlUp).Row
For X = 2 To Ur
If Cells(X, 5) Like "Collettore *" Then
Cells(X, 6) = Tot1
Tot1 = 0
Else
Tot1 = Tot1 + Cells(X, 6)
If Cells(X, 5) = "Collettore" Then Cells(X, 6) = Tot2
Tot2 = Tot2 + Cells(X, 6)
End If
Next X
End Sub
2) Non leggi bene>>>Apri il file, vai sul foglio che desideri. Premi ALt+F11 e inseriscilo sulla destra.
Significa NON in un MODULO
L'altra non poteva sommare a meno di modificarla radicalmente, comunque riallego pure
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("e:e")) Is Nothing Then
Dim R
R = Target.Row
If R <= 2 Then Exit Sub
Application.EnableEvents = False
If Target.Offset(0, 0).Value Like "Collettore*" Then
Range(Cells(R - 2, 1), Cells(R - 2, 100)).Insert
Range(Cells(R - 2, 1), Cells(R - 2, 100)).RowHeight = 14.25
Range(Cells(R - 1, 1), Cells(R - 1, 100)).RowHeight = 6
End If
Application.EnableEvents = True
End If
End Sub