Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2652 connectés 

  FORUM HardWare.fr
  Windows & Software
  Logiciels

  Excel VBA - Checkbox Dynamique avec Nom Variable - Probleme de Value

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Excel VBA - Checkbox Dynamique avec Nom Variable - Probleme de Value

n°2759018
KLMStylePr​oduction
Posté le 21-02-2008 à 09:32:57  profilanswer
 

bonjour j ai un probleme sur Excel VBA
j ai cree des Checkbox dynamique sur mon userform. le nombre et le nom varie en fonction d une variable
 

Code :
  1. Set Checkbox = Me.Controls.Add("forms.Checkbox.1" )
  2.                 With Checkbox
  3.                 .Name = "CheckBox_" & Info
  4.                 .Caption = Info
  5.                 .Value = Statut
  6.                 .Left = 142
  7.                 .Top = Info_Pro_Position + 15 * Info_Pro_Number
  8.                 .Width = 200
  9.                 .Enabled = True


 
dans cet userform , j ai creer unb bouton valider qui me permet de transferer les valeurs des Checkbox sur excel.
 

Code :
  1. Private Sub BNT_Validate_Click()
  2. Column_Nombre = Sheets("Commandes" ).Range("A1" ).End(xlToRight).Column
  3. 'transferer les valeurs sur Excel
  4.     For X = 2 To Column_Nombre
  5.         Info = Sheets("Commandes" ).Cells(1, X)
  6.         Checkbox_Name = "CheckBox_" & Info
  7.         Value = Controls.Item(Checkbox_Name).Value
  8.         Sheets("Commandes" ).Cells(2, X) = Value
  9.     Next X
  10. 'fermer la fenetre
  11.     Unload UserForm_Setting
  12. End Sub


 
C ets a ce moment que j ai un probleme, Excel m affiche qu il ne reconnait pas le nom de ma checkbox. J ai donc differente hypotheses :
- je ne sais pas comment "activer" les checkbox pour que je puisse y acceder a partir de Private Sub BNT_Validate_Click()
- je ne connais pas le ligne de code pour trouver le nom de la checkbox dynamique
- autre chose..
 
je vous donne le code complet pour avoir une vision d ensemble plus claire
Private Sub UserForm_Initialize()
 

Code :
  1. Column_Nombre = Sheets("Commandes" ).Range("A1" ).End(xlToRight).Column
  2.    
  3. 'Creer les checkbox pour Info Perso
  4.     ' creer le label Info perso
  5.         Info_Perso_Position = 15
  6.             Set Label = Me.Controls.Add("forms.Label.1" )
  7.                 With Label
  8.                 .Name = "Label_Perso_Info"
  9.                 .Caption = "Personnal Information"
  10.                 .Left = 12
  11.                 .Top = Info_Perso_Position
  12.                 .Width = 200
  13.             End With
  14.     Info_Perso_Number = 1
  15.     'Creer les checkbox pour Info Perso
  16.         For X = 1 To Column_Nombre
  17.             'calcul des variables
  18.                 Statut = Sheets("Commandes" ).Cells(2, X)
  19.                 Info_Type = Sheets("Commandes" ).Cells(3, X)
  20.                 Info = Sheets("Commandes" ).Cells(1, X)
  21.  
  22.              If Info_Type = "Perso" Then
  23.                     Dim Checkbox As Object
  24.                     Set Checkbox = Me.Controls.Add("forms.Checkbox.1" )
  25.                         With Checkbox
  26.                             .Name = "CheckBox_" & Info
  27.                             .Caption = Info
  28.                             .Value = Statut
  29.                             .Left = 24
  30.                             .Top = Info_Perso_Position + 15 * Info_Perso_Number
  31.                             .Width = 200
  32.                             .Enabled = True
  33.                         End With
  34.                 Info_Perso_Number = Info_Perso_Number + 1
  35.             End If
  36.         Next X
  37. 'Creer les checkbox pour Info Pro
  38.     Info_Pro_Position = 15
  39.             Set Label = Me.Controls.Add("forms.Label.1" ) ' creer le label Info Pro
  40.                 With Label
  41.                 .Name = "Label_Prof_Info"
  42.                 .Caption = "Professional Information"
  43.                 .Left = 130
  44.                 .Top = Info_Pro_Position
  45.                 .Width = 200
  46.             End With
  47.    
  48.     Info_Pro_Number = 1
  49. For X = 1 To Column_Nombre 'Creer les checkbox pour Info Pro
  50.     'calcul des variables
  51.         Statut = Sheets("Commandes" ).Cells(2, X)
  52.         Info_Type = Sheets("Commandes" ).Cells(3, X)
  53.         Info = Sheets("Commandes" ).Cells(1, X)
  54.    
  55.     If Info_Type = "Pro" Then
  56.         Set Checkbox = Me.Controls.Add("forms.Checkbox.1" )
  57.                 With Checkbox
  58.                 .Name = "CheckBox_" & Info
  59.                 .Caption = Info
  60.                 .Value = Statut
  61.                 .Left = 142
  62.                 .Top = Info_Pro_Position + 15 * Info_Pro_Number
  63.                 .Width = 200
  64.                 .Enabled = True
  65.         End With
  66.             Info_Pro_Number = Info_Pro_Number + 1
  67.     End If
  68. Next X
  69. End Sub
  70. Private Sub BNT_Validate_Click()
  71. Sheets("Commandes" ).Activate
  72. Column_Nombre = Sheets("Commandes" ).Range("A1" ).End(xlToRight).Column
  73. 'transferer les valeurs sur Excel
  74.     For X = 2 To Column_Nombre
  75.         Info = Sheets("Commandes" ).Cells(1, X)
  76.         Checkbox_Name = "CheckBox_" & Info
  77.         Value = Controls.Item(Checkbox_Name).Value
  78.         Sheets("Commandes" ).Cells(2, X) = Value
  79.     Next X
  80. 'fermer la fenetre
  81.     Unload UserForm_Setting
  82. End Sub


 
J espere que vous pourrez me donner des bons conseils.
 
A bientot
 
 
 
 
 
 
 

mood
Publicité
Posté le 21-02-2008 à 09:32:57  profilanswer
 

n°2759019
DraX
♪ | Membre raccourci | 12th
Posté le 21-02-2008 à 10:01:19  profilanswer
 

Ce sujet a été déplacé de la catégorie Hardware vers la categorie Windows & Software par DraCuLaX


---------------
| Un malentendu du cul | boum boum ! | La roulette

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Windows & Software
  Logiciels

  Excel VBA - Checkbox Dynamique avec Nom Variable - Probleme de Value

 

Sujets relatifs
[Problème de partition] Puis je supprimer ma partition FAT32 ?Problème au démarrage de windows X
Probleme pour eteindre/fermer une session sur vistaProblème multi-partition
Probleme hotfix...problème mode sans échec : help
Aide petit probleme au demarrage de windows XPprobleme de qualité du son
Probleme de gravure , cd illisible 
Plus de sujets relatifs à : Excel VBA - Checkbox Dynamique avec Nom Variable - Probleme de Value


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR