Ajout valeurs dans tableau macro

Bonjour,

J'ai une combobox qui vas chercher des valeurs dans un tableau, et si la valeur existe elle est sauvegarder dans le tableau, si elle ne l'est pas, elle est sauvegarder en dessous du tableau.Sauf que ma macro, fait les deux, elle enregistre dans et tableau et en dessous.

Ceci dépend de la condition :

If Cells(Lg4, "A") Like ComboBox_Nom And Cells(Lg4, "B") = ComboBox_Prenom Then

la sub qui posse problème :

Sub save()
Dim Lg4 As Long
Dim Lg5 As Long
Worksheets("GYM 2012").Select
For Lg4 = 2 To Range("A65536").End(xlUp).Row
        If Cells(Lg4, "A") Like ComboBox_Nom And Cells(Lg4, "B") = ComboBox_Prenom Then
        'enregsitre si déja existant dans tableau : pour modification
        Cells(Lg4, "C") = TextBox1
End If
Next Lg4

      If Cells(Lg4, "A") Like ComboBox_Nom And Cells(Lg4, "B") = ComboBox_Prenom Then
      'rien
      Else
        'chercher derniere ligne tableau
    Lg5 = Range("A65536").End(xlUp).Offset(1, 0).Row
        Cells(Lg5, "A") = ComboBox_Nom
        Cells(Lg5, "B") = ComboBox_Prenom
        Cells(Lg5, "C") = TextBox1
End Sub

Merci d'avance

Vincent

avec le fichier en PJ :

Bonjour

Modifies ta macro

Sub save()
Dim Lg4 As Long
Dim Lg5 As Long

Worksheets("GYM 2012").Select

  For Lg4 = 2 To Range("A65536").End(xlUp).Row
    If Cells(Lg4, "A") Like ComboBox_Nom And Cells(Lg4, "B") = ComboBox_Prenom Then
      'enregsitre si déja existant dans tableau : pour modification
      Cells(Lg4, "C") = TextBox1 * 1
      Exit Sub
    End If
  Next Lg4

  'chercher derniere ligne tableau
  Lg5 = Range("A65536").End(xlUp).Offset(1, 0).Row
        Cells(Lg5, "A") = ComboBox_Nom
        Cells(Lg5, "B") = ComboBox_Prenom
        Cells(Lg5, "C") = TextBox1 * 1
End Sub

Merci, tu a même résolu mon deuxième problème, qui était avec les chiffres, qui s'affichaient en "texte"

bonne soirée a vous

vincent

Rechercher des sujets similaires à "ajout valeurs tableau macro"