Re : Création d'un code produit
oui Ezrielle j'ai oublié au moins 2 choses dans le code
la comparaison dans la boucle for each cel, n'était pas bonne
et si n=0
Private Sub CommandButton1_Click() 'nouveau
Dim Cel As Range, Mot As String, MotC As String, N As Byte, Pos As Byte
If Me.TextBox2 <> "" Then
NaCodeInterne = ""
Pos = 0: N = 0
MotC = Mid(Me.NAgroupe, 1, 1) & "_" & Mid(Me.NAfamille, 1, 1)
Pos = InStr(Me.NAfamille, "-")
If Pos > 0 Then MotC = MotC & UCase(Mid(Me.NAfamille, Pos + 1, 1))
NAarticle.AddItem Me.TextBox2
NAarticle.Value = UCase(Me.TextBox2)
With Worksheets("Base")
For Each Cel In .Range("D2
" & .Range("D65536").End(xlUp).Row)
If Mid(Cel, 1, InStrRev(Cel, "_") - 1) = MotC Then
N = N + 1 'compte
End If
Next Cel
End With
'code interne suivant
If N = 0 Then
N = 1
Else: N = N + 1
End If
Mot = "000"
Mot = Mid(Mot, 1, Len(Mot) - Len(N)) 'enlève 0 en trop
Me.NaCodeInterne = MotC & "_" & Mot & N 'ajoute index
'code fournisseur
Me.NaCodeFournisseur = Mid(Me.NAarticle, 1, InStr(Me.NAarticle, "_") - 1)
End If
End Sub
soirée bonne,lecture
à bientôt