XL 2010 Joindre Caption Case à cocher

cathodique

XLDnaute Barbatruc
Bonjour,

Mes remerciements anticipés pour votre aide.

Là, je m'embrouille avec moi-même. Je sais que c'est simple mais ça bloque dans ma petite cervelle.

Je voudrais avoir une fonction qui joint les captions de cases à cocher si leur value est vrai, avec comme séparateur "/".
VB:
Dim ctrl As Object
For Each ctrl In FrmCat.Controls
      If TypeOf ctrl Is MSForms.CheckBox Then
         If ctrl.Value = True Then
          ' ici que bloque'
          'comme récupèrer dans une variable les captions séparés avec "/"'
         End If
      End If
   Next ctrl
Pour info, toutes les checkboxs sont dans une frame (frame1).

J'ai voulu utiliser la fonction JOIN mais je n'y arrive pas.

Encore merci.

ps: mes excuses anticipées si je ne réponds pas rapidement (indépendant de ma volonté).
 
Dernière édition:
Solution
Une fonction qui serait utilisable pour différents Frame à spécifier en paramètre :
VB:
Private Function CkxFrame(ByVal Frm As MSForms.Frame) As String
   Dim Ctrl As MSForms.Control, N As Integer, T() As String
   ReDim T(1 To Frm.Controls.Count)
   For Each Ctrl In Frm.Controls
      If TypeOf Ctrl Is MSForms.CheckBox Then
         If Ctrl.Value Then N = N + 1: T(N) = Ctrl.Caption
         End If
      Next Ctrl
   If N < 1 Then Exit Function
   ReDim Preserve T(1 To N)
   CkxFrame = Join(T, "/")
   End Function

Dranreb

XLDnaute Barbatruc
Bonjour.
VB:
Dim Ctrl As MSForms.Control, N As Integer, T() As String
ReDim T(1 To FrmCat.Controls.Count)
For Each Ctrl In FrmCat.Controls
   If TypeOf Ctrl Is MSForms.CheckBox Then
      If Ctrl.Value Then N = N + 1: T(N) = Ctrl.Caption
      End If
   Next Ctrl
ReDim Preserve T(1 To N)
Résultat = VBA.Join(T, "/")
 

cathodique

XLDnaute Barbatruc
Bonjour.
VB:
Dim Ctrl As MSForms.Control, N As Integer, T() As String
ReDim T(1 To FrmCat.Controls.Count)
For Each Ctrl In FrmCat.Controls
   If TypeOf Ctrl Is MSForms.CheckBox Then
      If Ctrl.Value Then N = N + 1: T(N) = Ctrl.Caption
      End If
   Next Ctrl
ReDim Preserve T(1 To N)
Résultat = VBA.Join(T, "/")
Bonsoir @Dranreb ;),

Le résultat est exactement ce que j'attendais.
J'ai utilisé une sub en déclarant Résultat en variable global.
Chose que je ne maîtrise pas bien et comment en faire une fonction.
VB:
Dim Résultat

Sub Categorie()
Dim Ctrl As MSForms.Control, N As Integer, T() As String
ReDim T(1 To FrmCat.Controls.Count)
For Each Ctrl In FrmCat.Controls
   If TypeOf Ctrl Is MSForms.CheckBox Then
      If Ctrl.Value Then N = N + 1: T(N) = Ctrl.Caption
      End If
   Next Ctrl
ReDim Preserve T(1 To N)
Résultat = VBA.Join(T, "/")
End Sub

Merci beaucoup.

Bonne soirée.
 

Dranreb

XLDnaute Barbatruc
Une fonction qui serait utilisable pour différents Frame à spécifier en paramètre :
VB:
Private Function CkxFrame(ByVal Frm As MSForms.Frame) As String
   Dim Ctrl As MSForms.Control, N As Integer, T() As String
   ReDim T(1 To Frm.Controls.Count)
   For Each Ctrl In Frm.Controls
      If TypeOf Ctrl Is MSForms.CheckBox Then
         If Ctrl.Value Then N = N + 1: T(N) = Ctrl.Caption
         End If
      Next Ctrl
   If N < 1 Then Exit Function
   ReDim Preserve T(1 To N)
   CkxFrame = Join(T, "/")
   End Function
 

cathodique

XLDnaute Barbatruc
Une fonction qui serait utilisable pour différents Frame à spécifier en paramètre :
VB:
Private Function CkxFrame(ByVal Frm As MSForms.Frame) As String
   Dim Ctrl As MSForms.Control, N As Integer, T() As String
   ReDim T(1 To Frm.Controls.Count)
   For Each Ctrl In Frm.Controls
      If TypeOf Ctrl Is MSForms.CheckBox Then
         If Ctrl.Value Then N = N + 1: T(N) = Ctrl.Caption
         End If
      Next Ctrl
   ReDim Preserve T(1 To N)
   CkxFrame = Join(T, "/")
   End Function
Merci beaucoup. Oui une fonction réutilisable. C'est parfait pour moi.

Bonne soirée.
 

Statistiques des forums

Discussions
312 836
Messages
2 092 651
Membres
105 479
dernier inscrit
chaussadas.renaud