Public Scrol As Object
Sub AjoutLigne()
Application.ScreenUpdating = False
'ActiveSheet.Unprotect Password:="LN"
Scrol.Placement = 2 'dimensions scrollbar figées
Set def = Range("def" & Right(Scrol.Name, 1)).Cells
Set ins = Range("ins" & Right(Scrol.Name, 1)).Cells
H = def.Count - 1
If def.Count < Scrol Then
Answer = MsgBox(Prompt:="Voulez-vous ajouter un mois ?", Buttons:=vbYesNo + vbQuestion)
If Answer = vbYes Then
ins(1).EntireRow.Insert
ins(1).Offset(-2, 0).EntireRow.Copy
ins(1).Offset(-1, 0).EntireRow.PasteSpecial xlPasteFormats
Range(Cells(ins.Offset(-2, 0).Row, "B"), Cells(ins.Offset(-1, 0).Row, "Y")).Borders(xlInsideHorizontal).LineStyle = xlContinuous
Range(Cells(ins.Offset(-2, 0).Row, "B"), Cells(ins.Offset(-1, 0).Row, "Y")).Borders(xlInsideHorizontal).Weight = xlThin
For i = 2 To 17
ins.Offset(0, i).FormulaR1C1 = "=SUM(R[-" & H + 1 & "]C:R[-1]C)"
Next
ins.Offset(0, 11).ClearContents: ins.Offset(0, 12).ClearContents
Cells(ActiveCell.Row, 16).FormulaR1C1 = Cells(ActiveCell.Row - 1, 16).FormulaR1C1
ins.Select
End If
Else
For i = 2 To H 'pour toutes les lignes insérées en commencant par la première
lig = Range(def(i), def(i)).Row 'lig définit numéro de cette ligne
x = Application.WorksheetFunction.CountA(Rows(lig)) 'x=nombre de valeurs dans cette ligne
If x = 1 Then def(i).EntireRow.Delete: Exit For 'si la ligne est renseignée (x>0), passe à la ligne suivante, sinon supprime la ligne et sort de la boucle
Next
End If
[COLOR="Red"]Scrol = def.Count[/COLOR]
Scrol.Placement = 1 'dimensions scrollbar fonction des cellules
Application.ScreenUpdating = True
'ActiveSheet.Protect Password:="LN"
End Sub