Bonjour à toutes et à tous, tout est dit dans le titre, je vous joints mon code.
Merci pour votre aide.
Merci pour votre aide.
Code:
Private Sub CommandButton3_click()
Application.ScreenUpdating = False
Dim dernLign As Long
Dim NB&, cell As Range
Dim i As Integer
Dim J As Integer
Dim PAILLE As String
Dim MAIS As String
Dim LAIT As String
Dim FIBRA As String
Dim MELANGE As String
NB = 0
With Sheets("Alimentation")
'On mémorise dans DernLign le numéro de la première ligne libre de la feuille Alimentation
dernLign = .Cells(.Rows.Count, 4).End(xlUp).Row + 1
'On met à jour la feuille Alimentation avec les données du Userform
If TextBox6.Value = "" Then
TextBox6.Value = 0
Else
If .Cells(dernLign, 2).Value = "FIBRA" Then
.Cells(dernLign, 4).Value = TextBox6.Value * 1250
If .Cells(dernLign, 2).Value = "MAIS" Then
.Cells(dernLign, 4).Value = TextBox6.Value * 1250
If .Cells(dernLign, 2).Value = "LAIT" Then
.Cells(dernLign, 4).Value = TextBox6.Value * 1500
If .Cells(dernLign, 2).Value = "PAILLE" Then
.Cells(dernLign, 4).Value = TextBox6.Value * 1050
End If
End If
End If
End If
End If
With Sheets("Identifiants")
For Each cell In .Range("F2:F65536")
If cell <> "" Then NB = NB + 1
Next cell
With Sheets("Alimentation")
If TextBox8.Value = "" Then
'Si la TextBox8 est vide , je mais 0 dans colonne E
.Cells(dernLign, 5).Value = 0
ElseIf TextBox8.Value <> "" Then
'Si la TextBox8 est <> de vide , je mais sa valeur dans colonne E
dernLign = .Cells(.Rows.Count, 5).End(xlUp).Row + 1
Cells(2, 12).Value = TextBox8.Value
.Cells(dernLign, 5).Value = NB * Cells(2, 12) / 1000
If .Cells(dernLign, 5).Value = NB * Cells(2, 12) / 1000 < 25 Then
.Cells(dernLign, 5).Value = 25
'Ici si le résultat est < à 25, je mais 25 et si il est > 25 je mets 50 ( multiple de 25)
End If
.Cells(dernLign, 6).Value = .Cells(dernLign, 4).Value - .Cells(dernLign, 5).Value
'Ici je calcule, mais dand le cas où la TextBox8 est vide, il ne fait pas le calcul.
For i = 3 To Range("B65536").End(xlUp).Row
For J = 3 To 6
If Range("H" & J) = Range("B" & i) Then Range("I" & J) = Range("F" & i)
Next J
Next i
Application.ScreenUpdating = True
End If
End With
End With
End With
End Sub