Passage d'une variable avec Call

Résolu
theflolyon Messages postés 11 Date d'inscription mardi 8 juillet 2008 Statut Membre Dernière intervention 27 février 2010 - 18 juil. 2008 à 13:08
theflolyon Messages postés 11 Date d'inscription mardi 8 juillet 2008 Statut Membre Dernière intervention 27 février 2010 - 21 juil. 2008 à 10:51
Bonjour a tous.

j'ai créé une subtextdansliste pour enregistrer des données saisies dans des textbox dans une feuille excel.
Sub Textdansliste()

        Cells(i, 1) = TextBox_a.Text

        Cells(i, 2) = Textbox_b.Text

        Cells(i, 3) = Textbox_c.Text

        Cells(i, 4) = TextBox_d.Text

        Cells(i, 5) = TextBox_e.Text

        Cells(i, 6) = TextBox_f.Text

        Cells(i, 7) = TextBox_g.Text

        Cells(i, 8) = TextBox_h.Text

        Cells(i, 9) = TextBox_i.Text

        Cells(i, 10) = TextBox_j.Text

        Cells(i, 11) = TextBox_k.Text

        Cells(i, 12) = TextBox_l.Text

        Cells(i, 13) = TextBox_m.Text

        Cells(i, 14) = TextBox_n.Text

        Cells(i, 15) = TextBox_o.Text

        Cells(i, 16) = TextBox_p.Text

        Cells(i, 17) = TextBox_q.Text

        Cells(i, 18) = TextBox_r.Text

        Cells(i, 19) = TextBox_s.Text

        Cells(i, 20) = TextBox_t.Text

        Cells(i, 21) = TextBox_u.Text

        Cells(i, 22) = TextBox_v.Text

        Cells(i, 23) = TextBox_w.Text

        Cells(i, 24) = TextBox_x.Text

        Cells(i, 25) = TextBox_y.Text

       

End Sub

Cette sub me sert dans deux cas :
- quand on clique sur "modifier"
Private Sub modifier_Click()

i = ListBox1.ListIndex + 2
If i = 1 Then
        MsgBox ("Aucune coordonnée à modifier. Utilisez le bouton Ajouter")
       
    Else
        If MsgBox("Enregistrer les modifications ?", vbYesNo) = vbYes Then
            Call Textdansliste
        End If
End If
Call rafraichir
End Sub

 - quand on clique sur "valider" en cas d'ajout
Private Sub valider_Click()

i = Worksheets("Entreprise").Cells(1, 1).End(xlDown).Row + 1

Call Textdansliste
Call rafraichir
End Sub

hors, ce code ne marche pas. Il me semble que  la subtextdansliste  ne reconnais pas la variable  i

Existe t'il un moyen de "faire passer une variable" d'un sub à l'autre quand on utilise la fonction Call ?
Existe il une manière plus "propre" d'écrire la sub textdansliste ?(en indexant les textbox par exemple, pour utiliser une boucle)

Merci d'avance.
... Toujours apprendre, jamais dépendre ...

2 réponses

mortalino Messages postés 6786 Date d'inscription vendredi 16 décembre 2005 Statut Membre Dernière intervention 21 décembre 2011 18
18 juil. 2008 à 13:12
Salut,

oui c'est possible.

Sub TexteDansListe(ByVal sTexte As String)
.. ton traitement
Msgbox sTexte
End Sub

Et pour l'appeler :

Call TexteDansListe("Salut")
ou
blabla = "Salut"
Call TexteDansListe(blabla)

@++

le mystérieux chevalier,"Provençal, le gaulois"
Forum Office & VBA
3
theflolyon Messages postés 11 Date d'inscription mardi 8 juillet 2008 Statut Membre Dernière intervention 27 février 2010
21 juil. 2008 à 10:51
Merci ça marche parfaitement !!!

... Toujours apprendre, jamais dépendre ...
0
Rejoignez-nous