Récupérer une variable

Magic_Doctor

XLDnaute Barbatruc
Bonjour à tous,

Comment faire pour récupérer une variable, ou comment doit-on la déclarer ?
Je m'explique :
J'ai un USF
Je déclare une variable "vol%" pour un ComboBox :

--------------------------------------------------------------------------
Private Sub ComboBox1_Change()

Dim vol%, Cel As Range

Set Cel = [ListeDilutions].Cells(ComboBox1.ListIndex + 1, 1)

vol% = Right(Cel.Value, Len(Cel.Value) - InStr(1, Cel.Value, "/", 0))

etc......................................

End Sub
--------------------------------------------------------------------------

Seulement, pour un CommandButton, j'ai besoin de la même variable avec la même valeur.
Bien sûr, je peux à nouveau répéter dans la procédure du CommandButton ce que j'avais déjà écrit auparavant. Mais peut-on éviter cette lourde redondance ?

Pour toute réponse, un grand merci !
 

Banzai64

XLDnaute Accro
Re : Récupérer une variable

Bonjour

Il suffit de déclarer ta variable en Public
Places la en dehors d'une procédure (En haut de ta page de code)
et il faut supprimer sa déclaration dans la procédure

Code:
Option Explicit

Public Vol%

Private Sub ComboBox1_Change()
Dim [COLOR="Red"]vol%,[/COLOR] Cel As Range

Set Cel =[ListeDilutions].Cells(ComboBox1.ListIndex + 1, 1)
vol% = Right(Cel.Value, Len(Cel.Value) - InStr(1, Cel.Value, "/", 0))
etc......................................
End Sub
 

Discussions similaires

Réponses
1
Affichages
145

Statistiques des forums

Discussions
312 328
Messages
2 087 318
Membres
103 515
dernier inscrit
Cherbil12345