Ajout des données en respectant la numerotation

FaruSZ

XLDnaute Occasionnel
Bonjour,

j'ai le tableau ci-dessous:
Capture.JPG

Je veux ajouter des lames a ma colonne B, en précisant le numéro de la lame après l'avoir choisi a partir d'une comobobox, si le N° est 005 la lame doit se mettre en colonne B ligne 6, si le N° est 006, lame se rajoute en colonne B ligne 7...

j'ai rédigé le code suivant:
VB:
Private Sub CommandButton1_Click()
Dim fin_liste As Range, ligne As Long, ws_lame As Worksheet, ctrl As Boolean
Set ws_lame = ActiveWorkbook.Worksheets("Liste_Lame_" & Me.ComboBox_Modele.Value)
Set fin_liste = ThisWorkbook.Worksheets("Liste_Lame_" & Me.ComboBox_Modele.Value).Cells(Rows.Count, "B").End(xlUp).Offset(1, 0)
For j = 2 To fin_liste
    If ws_lame.Range("A" & j) = Me.ComboBox_Num.Value Then
        ctrl = True
        fin_liste = Me.ComboBox_Num.Value & "-" & Me.TextBox_Mois.Value & "-" & Me.TextBox_Annee.Value & "-" & Me.ComboBox_Modele.Value & "-" & Me.ComboBox_Const.Value
Exit For
    End If
Next
If ctrl = False Then
    j = fin_liste + 1
    ws_lame.Range("A" & j).Value = Me.ComboBox_Num.Value
    fin_liste = Me.ComboBox_Num.Value & "-" & Me.TextBox_Mois.Value & "-" & Me.TextBox_Annee.Value & "-" & Me.ComboBox_Modele.Value & "-" & Me.ComboBox_Const.Value
End If
End Sub

il me rajoute les lames directement sans prendre en compte le numéro que j'ai choisi, que dois je modifier dans mon code ? Merci

Rmq: J'ai 4 feuilles liste_lameM1, liste_lameM2, liste_lameM3 et liste_lameM4 d'où la définition de fin_liste : fin_liste = ThisWorkbook.Worksheets("Liste_Lame_" & Me.ComboBox_Modele.Value).Cells(Rows.Count, "B").End(xlUp).Offset(1, 0), en précisant le modèle, la lame se rajoute dans la bonne feuille.
 

Pièces jointes

  • Gestion_Lames.xlsm
    75.6 KB · Affichages: 5

FaruSZ

XLDnaute Occasionnel
Probléme resolu, solution :
VB:
Private Sub CommandButton1_Click()
Dim Cible As Range

With ActiveWorkbook.Worksheets("Liste_Lame_" & Me.ComboBox_Modele.Value)
    Set Cible = .Cells(CInt(Me.ComboBox_Num.Value) + 1, 2)
    Cible = Me.ComboBox_Num.Value & "-" & Me.TextBox_Mois.Value & "-" & Me.TextBox_Annee.Value & "-" & Me.ComboBox_Modele.Value & "-" & Me.ComboBox_Const.Value
    If Cible.Offset(0, -1) = "" Then Cible.Offset(0, -1).Value = Me.ComboBox_Num.Value
End With

End Sub
 

Discussions similaires

Statistiques des forums

Discussions
312 196
Messages
2 086 099
Membres
103 116
dernier inscrit
kutobi87