bonjour,
Private Sub CommandButton2_Click()
Dim i As Integer
Dim ajout As Long
ajout = 6
With Sheets("La Nature Géologique")
i = Application.Min(Application.Max(1, Me.Label12.Caption - 1), .Range("I7").Value) ' 1<= i <= range("I7") !!!
TextBox3.Value = .Range("c" & ajout + i).Value
TextBox4.Value = .Range("c" & ajout).Offset(i, 1).Value
TextBox5.Value = .Range("c" & ajout).Offset(i, 3).Value
TextBox6.Value = .Range("c" & ajout).Offset(i, 4).Value
Me.Label12.Caption = i
End With
End Sub
Private Sub CommandButton3_Click()
Dim i As Integer
Dim ajout As Integer
'ajout = Range("B" & Rows.Count).End(xlUp).Row + 1
'Rows(ajout).Insert 'insertion d'une ligne juste en dessous du tableau
i = Me.Label12.Caption
If i = 1 Then
Me.TextBox3.Value = 0
Me.TextBox3.Enabled = False
End If
With Sheets("La Nature Géologique")
If WorksheetFunction.Median(1, i, .Range("i7").Value) = i Then ' 1<= i <= range("I7") ?
ajout = 6
.Range("i7") = TextBox1
.Range("j7") = TextBox2
.Range("c" & ajout + i).Value = TextBox3.Value
.Range("c" & ajout).Offset(i, 1).Value = TextBox4.Value
.Range("c" & ajout).Offset(i, 3).Value = TextBox5.Value
.Range("c" & ajout).Offset(i, 4).Value = TextBox6.Value
.Range("c" & ajout).Offset(i, -1).Value = i
End If
i = Application.Min(Application.Max(1, Me.Label12.Caption + 1), .Range("I7").Value) ' 1<= i <= range("I7") !!!
Me.Label12.Caption = i
TextBox3.Value = .Range("c" & ajout).Offset(i - 1, 1).Value
TextBox4.Value = .Range("c" & ajout).Offset(i, 1).Value
TextBox5.Value = .Range("c" & ajout).Offset(i, 3).Value
TextBox6.Value = .Range("c" & ajout).Offset(i, 4).Value
End With
End Sub
Private Sub TextBox1_Change()
'If TextBox1 <> "" And TextBox1 > 9 Then MsgBox "le nombre de couche maximum est de 9": Exit Sub
Sheets("La Nature Géologique").Range("i7") = TextBox1
End Sub
avec cette ligne, vous pouvez limitez i entre un minimim et un maximum
i = Application.Min(Application.Max(1, Me.Label12.Caption - 1), .Range("I7").Value) ' 1<= i <= range("I7") !!!