Probleme pour copier des valeur depuis une textbox

Résolu/Fermé
phileas25 Messages postés 6 Date d'inscription vendredi 11 mars 2016 Statut Membre Dernière intervention 11 octobre 2016 - 24 mars 2016 à 13:27
 phileas25 - 25 mars 2016 à 19:38
Bonjour a tous, j'ai a nouveau besoin de vos lumieres:
j'ai un petit programme qui marche à moitié et je ne sais vraiment pas pourquoi, les memes instructions marchent pour 3 cas sur sept.
si quelqu'un peut m'expliquer ce qui ne va pas , un grand merci d'avance


Private Sub UserForm_Initialize()
For i = 3 To 9
tri.AddItem Sheets("tri").Cells(2, i)
Next
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

If IsNumeric(TextBox1.Text) = False Then
MsgBox ("Vous ne devez saisir que des chiffres")
End If


End Sub
Private Sub TextBox2_AfterUpdate()
If tri.Value = "1 CAPITAUX" Then
no_ligne = Sheets("tri").Range("c65536").End(xlUp).Row + 1
TextBox3.Value = TextBox1.Value & " " & TextBox2.Value
Sheets("tri").Cells(no_ligne, 3).Value = TextBox3.Value

ElseIf tri.Value = "2 IMMOBILISATION" Then
no_ligne = Sheets("tri").Range("d65536").End(xlUp).Row + 1
TextBox3.Value = TextBox1.Value & " " & TextBox2.Value
Sheets("tri").Cells(no_ligne, 4).Value = TextBox3.Value



ElseIf tri.Value = "3 STOCK et EN-COURS" Then
no_ligne = Sheets("tri").Range("e65536").End(xlUp).Row + 1
TextBox3.Value = TextBox1.Value & " " & TextBox2.Value
Sheets("tri").Cells(no_ligne, 5).Value = TextBox3.Value



ElseIf tri.Value = "4 COMPTES TIERS " Then
no_ligne = Sheets("tri").Range("f65536").End(xlUp).Row + 1
TextBox3.Value = TextBox1.Value & " " & TextBox2.Value
Sheets("tri").Cells(no_ligne, 6).Value = TextBox3.Value


ElseIf tri.Value = "5 COMPTES FINANCIERS " Then
no_ligne = Sheets("tri").Range("g65536").End(xlUp).Row + 1
TextBox3.Value = TextBox1.Value & " " & TextBox2.Value
Sheets("tri").Cells(no_ligne, 7).Value = TextBox3.Value


ElseIf tri.Value = "6 COMPTES de CHARGES " Then
no_ligne = Sheets("tri").Range("h65536").End(xlUp).Row + 1
TextBox3.Value = TextBox1.Value & " " & TextBox2.Value
Sheets("tri").Cells(no_ligne, 8).Value = TextBox3.Value


ElseIf tri.Value = "7 COMPTES de PRODUITS " Then
no_ligne = Sheets("tri").Range("i65536").End(xlUp).Row + 1
TextBox3.Value = TextBox1.Value & " " & TextBox2.Value
Sheets("tri").Cells(no_ligne, 9).Value = TextBox3.Value
End If


End Sub
Private Sub arret_Click()
Unload Me
End Sub
Private Sub nouveau_Click()
Unload Me
UserForm1.Show
End Sub
A voir également:

1 réponse

gbinforme Messages postés 14946 Date d'inscription lundi 18 octobre 2004 Statut Contributeur Dernière intervention 24 juin 2020 4 684
25 mars 2016 à 10:48
Bonjour,

Je te suggère cette macro qui devrait fonctionner :
Private Sub TextBox2_AfterUpdate()
    If tri.ListIndex < 0 Then Exit Sub
    no_ligne = Sheets("tri").Cells(Rows.Count, tri.ListIndex + 3).End(xlUp).Row + 1
    TextBox3.Value = TextBox1.Value & " " & TextBox2.Value
    Sheets("tri").Cells(no_ligne, tri.ListIndex + 3).Value = TextBox3.Value
End Sub
0
Merci d'avoir pris du temps pour me repondre, en fait j'avais des blancs en trop dans mes critères, maintenant ca marche parfaitement. Encore merci a toi
0