Excel vba checkbox et combobox
JuJuK
Messages postés
21
Statut
Membre
-
f894009 Messages postés 17417 Date d'inscription Statut Membre Dernière intervention -
f894009 Messages postés 17417 Date d'inscription Statut Membre Dernière intervention -
bonjour
alors voila j'ai un problème que je n'arrive pas régler depuis quelques jours
grâce à une macro j'ai un certain nombre de checkbox créées dynamiquement grâce a OLEObject, chaque checkbox est associée à une combobox que j'initialise sur visible = false mon but est donc d'afficher la combobox qd ma checkbox est cochée j'ai essayé de plusieurs façon mais je n'arrive pas à obtenir le résultat voulu si quelqu'un peut m'aider...
merci
voila un bout de mon code
For i = 7 To total_ligne_tcd
With ActiveSheet.Range("G" & i)
Set c = ActiveSheet.OLEObjects.Add(ClassType:="Forms.Check Box.1", Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height)
c.Name = "CheckBox_" & i
End With
With ActiveSheet.Range("H" & i)
Set d = ActiveSheet.OLEObjects.Add(ClassType:="Forms.Combo Box.1", Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height)
d.Name = "ComboBox_" & i
d.Visible = False
End With
ps : je travaille sous excel 2007 mais j enregistre en excel 2003 et je n'utilise pas de userform
Nextfig>
alors voila j'ai un problème que je n'arrive pas régler depuis quelques jours
grâce à une macro j'ai un certain nombre de checkbox créées dynamiquement grâce a OLEObject, chaque checkbox est associée à une combobox que j'initialise sur visible = false mon but est donc d'afficher la combobox qd ma checkbox est cochée j'ai essayé de plusieurs façon mais je n'arrive pas à obtenir le résultat voulu si quelqu'un peut m'aider...
merci
voila un bout de mon code
For i = 7 To total_ligne_tcd
With ActiveSheet.Range("G" & i)
Set c = ActiveSheet.OLEObjects.Add(ClassType:="Forms.Check Box.1", Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height)
c.Name = "CheckBox_" & i
End With
With ActiveSheet.Range("H" & i)
Set d = ActiveSheet.OLEObjects.Add(ClassType:="Forms.Combo Box.1", Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height)
d.Name = "ComboBox_" & i
d.Visible = False
End With
ps : je travaille sous excel 2007 mais j enregistre en excel 2003 et je n'utilise pas de userform
Nextfig>
A voir également:
- Excel vba checkbox et combobox
- Word et excel gratuit - Guide
- Liste déroulante excel - Guide
- Si et ou excel - Guide
- Excel compter cellule couleur sans vba - Guide
- Déplacer colonne excel - Guide
19 réponses
Bonjour,
VBA de le feuille ou vous avez cree vos objets:
ex:
Private Sub checkbox1_Click()
ComboBox1.Visible = Not ComboBox1.Visible
End Sub
ou
Dans un module:
If Sheets(1).OLEObjects("CheckBox2").Object Then
Sheets(1).OLEObjects("Combobox1").Visible = True
End If
A+
VBA de le feuille ou vous avez cree vos objets:
ex:
Private Sub checkbox1_Click()
ComboBox1.Visible = Not ComboBox1.Visible
End Sub
ou
Dans un module:
If Sheets(1).OLEObjects("CheckBox2").Object Then
Sheets(1).OLEObjects("Combobox1").Visible = True
End If
A+
voila mon code entier
Sub auto()
Dim fichier1 As Variant
Dim total_ligne_tcd As Integer
Dim c As OLEObject
Dim d As OLEObject
Dim i As Integer
Dim ligne As Integer
fichier1 = Application.GetOpenFilename("Fichier (*.*), *.*")
If fichier1 = False Then
MsgBox "erreur de fichier Excel"
Exit Sub
End If
Workbooks.Open (fichier1)
Sheets("Smp99_Donnees").Select
Sheets("Smp99_Donnees").Activate
Sheets("Smp99_Donnees").Move _
Before:=Workbooks("Classeur1.xls").Sheets(3)
'Comptage du nombre d'arrets
Sheets("Smp99_Donnees").Select
ligne = 8
dat = Cells(ligne, 2)
Do While dat <> ""
ligne = ligne + 1
dat = Cells(ligne, 2)
Loop
total_ligne = ligne - 1
Range("B8").Select
'tableau dynamique
Sheets("Smp99_Donnees").Select
Range(Cells(7, 2), Cells(total_ligne, 40)).Select
ActiveWorkbook.Names.Add Name:="tcd_tcd", RefersToR1C1:= _
Range(Cells(7, 2), Cells(total_ligne, 40))
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"tcd_tcd").CreatePivotTable TableDestination:="Feuil2!R5C1", TableName:= _
"Tableau croisé dynamique", DefaultVersion:=xlPivotTableVersion10
Sheets("Feuil2").Select
Cells(5, 1).Select
ActiveSheet.PivotTables("Tableau croisé dynamique").AddDataField ActiveSheet. _
PivotTables("Tableau croisé dynamique").PivotFields("Durée"), "Somme de Durée" _
, xlSum
With ActiveSheet.PivotTables("Tableau croisé dynamique").PivotFields("Type")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("Tableau croisé dynamique").PivotFields("Zone")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("Tableau croisé dynamique").PivotFields( _
"Evénement")
.Orientation = xlRowField
.Position = 3
End With
With ActiveSheet.PivotTables("Tableau croisé dynamique").PivotFields( _
"Commentaire")
.Orientation = xlRowField
.Position = 4
End With
ActiveWorkbook.Sheets("Feuil2").Select
ligne = 7
dat = Cells(ligne, 5)
Do While dat <> ""
ligne = ligne + 1
dat = Cells(ligne, 5)
Loop
total_ligne_tcd = ligne - 1
For i = 7 To total_ligne_tcd
With ActiveSheet.Range("G" & i)
Set c = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CheckBox.1", Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height)
c.Name = "CheckBox_" & i
End With
With ActiveSheet.Range("H" & i)
Set d = ActiveSheet.OLEObjects.Add(ClassType:="Forms.ComboBox.1", Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height)
d.Name = "ComboBox_" & i
d.Visible = False
End With
Next
End Sub
j'ai essayé avec
For i = 7 To total_ligne_tcd
If ActiveSheet.OLEObjects("CheckBox_" & i).Object.Value = True Then
ActiveSheet.OLEObjects("ComboBox_" & i).Object.Visible = True
End If
Next
mais ca ne marche tjs pas
Sub auto()
Dim fichier1 As Variant
Dim total_ligne_tcd As Integer
Dim c As OLEObject
Dim d As OLEObject
Dim i As Integer
Dim ligne As Integer
fichier1 = Application.GetOpenFilename("Fichier (*.*), *.*")
If fichier1 = False Then
MsgBox "erreur de fichier Excel"
Exit Sub
End If
Workbooks.Open (fichier1)
Sheets("Smp99_Donnees").Select
Sheets("Smp99_Donnees").Activate
Sheets("Smp99_Donnees").Move _
Before:=Workbooks("Classeur1.xls").Sheets(3)
'Comptage du nombre d'arrets
Sheets("Smp99_Donnees").Select
ligne = 8
dat = Cells(ligne, 2)
Do While dat <> ""
ligne = ligne + 1
dat = Cells(ligne, 2)
Loop
total_ligne = ligne - 1
Range("B8").Select
'tableau dynamique
Sheets("Smp99_Donnees").Select
Range(Cells(7, 2), Cells(total_ligne, 40)).Select
ActiveWorkbook.Names.Add Name:="tcd_tcd", RefersToR1C1:= _
Range(Cells(7, 2), Cells(total_ligne, 40))
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"tcd_tcd").CreatePivotTable TableDestination:="Feuil2!R5C1", TableName:= _
"Tableau croisé dynamique", DefaultVersion:=xlPivotTableVersion10
Sheets("Feuil2").Select
Cells(5, 1).Select
ActiveSheet.PivotTables("Tableau croisé dynamique").AddDataField ActiveSheet. _
PivotTables("Tableau croisé dynamique").PivotFields("Durée"), "Somme de Durée" _
, xlSum
With ActiveSheet.PivotTables("Tableau croisé dynamique").PivotFields("Type")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("Tableau croisé dynamique").PivotFields("Zone")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("Tableau croisé dynamique").PivotFields( _
"Evénement")
.Orientation = xlRowField
.Position = 3
End With
With ActiveSheet.PivotTables("Tableau croisé dynamique").PivotFields( _
"Commentaire")
.Orientation = xlRowField
.Position = 4
End With
ActiveWorkbook.Sheets("Feuil2").Select
ligne = 7
dat = Cells(ligne, 5)
Do While dat <> ""
ligne = ligne + 1
dat = Cells(ligne, 5)
Loop
total_ligne_tcd = ligne - 1
For i = 7 To total_ligne_tcd
With ActiveSheet.Range("G" & i)
Set c = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CheckBox.1", Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height)
c.Name = "CheckBox_" & i
End With
With ActiveSheet.Range("H" & i)
Set d = ActiveSheet.OLEObjects.Add(ClassType:="Forms.ComboBox.1", Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height)
d.Name = "ComboBox_" & i
d.Visible = False
End With
Next
End Sub
j'ai essayé avec
For i = 7 To total_ligne_tcd
If ActiveSheet.OLEObjects("CheckBox_" & i).Object.Value = True Then
ActiveSheet.OLEObjects("ComboBox_" & i).Object.Visible = True
End If
Next
mais ca ne marche tjs pas
Re,
A+
For i = 7 To total_ligne_tcd
If ActiveSheet.OLEObjects("CheckBox_" & i).Object.Value = True Then
ActiveSheet.OLEObjects("ComboBox_" & i).Visible = True
End If
Next i
A+
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
Re,
Hélas ça ne marche toujours pas...j'ai aussi essayé en associant à ma checkbox une cellule qui récupère true or false et puis faire un test sur cette dernière mais toujours rien je ne comprend pas ce qui ne va pas :(
merci de votre aide
Hélas ça ne marche toujours pas...j'ai aussi essayé en associant à ma checkbox une cellule qui récupère true or false et puis faire un test sur cette dernière mais toujours rien je ne comprend pas ce qui ne va pas :(
merci de votre aide
ce bouton est dans la première feuille de mon classeur, ensuite mon tableau croisé dynamique se crée dans la seconde feuille de ce dernier...la génération du tcd ainsi que des checkbox marche (et même celle des combobox qd je les mets en visible = true)
Re,
Il faut eviter ActiveSheet quand vous naviguez sur plusieurs feuilles
A+
Il faut eviter ActiveSheet quand vous naviguez sur plusieurs feuilles
With WorkSheets("nom_de_votre_feuille")
For i = 7 To total_ligne_tcd
If .OLEObjects("CheckBox_" & i).Object.Value = True Then
.OLEObjects("ComboBox_" & i).Visible = True
End If
Next i
End With
A+
Re,
Est-t-il possible d'avoir votre fichier avec seulement la creation des objets et votre bouton plus son code (peut-etre que vos donnees sont "sensibles") comme vous l'avez actuellement
lien https://www.cjoint.com/ et copier le lien de votre fichier
Est-t-il possible d'avoir votre fichier avec seulement la creation des objets et votre bouton plus son code (peut-etre que vos donnees sont "sensibles") comme vous l'avez actuellement
lien https://www.cjoint.com/ et copier le lien de votre fichier
lien du fichier
https://www.cjoint.com/?BImlDQof6Gw
lien de la feuille excel a insérer
https://www.cjoint.com/?BImlFacn0an
https://www.cjoint.com/?BImlDQof6Gw
lien de la feuille excel a insérer
https://www.cjoint.com/?BImlFacn0an
Re,
Je vous ai un peu modifie votre fichier, a vous de voir.
Pour lancer: onglet Accueil----> Bouton Départ
https://www.cjoint.com/?BImnDBI4i06
A+
Je vous ai un peu modifie votre fichier, a vous de voir.
Pour lancer: onglet Accueil----> Bouton Départ
https://www.cjoint.com/?BImnDBI4i06
A+
Re,
essayez celui-ci, quelques modifs, mais pas significatives de votre anomalie
https://www.cjoint.com/?BImpnLWWamN
essayez celui-ci, quelques modifs, mais pas significatives de votre anomalie
https://www.cjoint.com/?BImpnLWWamN