Contrôles dans le tableur avec BO Contrôles

Accueil

ComboBox
ComboBoxavec Maj immédiate si ajout dans liste
ComboBoxTrie
ComboBox 2 colonnes
CaseCocher
GroupeOptions
CheckBoxIndices
Choix ordre de Tri
Choix onglet combo
Positionnement sur un nom

ComboBox

BOcontroles

1- Créer un nom de champ dynamique:ListeCombo
=DECALER($B$2;;;NBVAL($B:$B)-1)

2- Faire apparaître la boite à outils contrôles :Affichage/Barre outils/boîte à outils contrôles

3-Dans les propriétés du combo (clic-droit combobox)
-dans la propriété ListFillRange, le nom du champ: ListeCombo
-dans la propriété LinkedCell:D5

4- Pour voir le résultat
Cliquer sur l'équerre pour qu'elle ne soit pas enfoncée.

ComboBox avec Maj immédiate si ajout dans liste

Créer un nom de champ dynamique MaListe

=DECALER($D$2;;;NBVAL($D:$D)-1)

Private Sub ComboBox1_DropButtonClick()
  ComboBox1.List = Range("maliste").Value
End Sub

Private Sub ComboBox1_Change()
  MsgBox "Change"
End Sub

ComboBox trié

Le tri est fait dans la feuille

Private Sub ComboBox1_DropButtonClick()
  [B2:B1000].Sort key1:=[B2]
  Me.ComboBox1.List = Range("ListeComboTrié").Value
End Sub

Private Sub ComboBox1_Change()
  [F1] = Me.ComboBox1
End Sub

Le tri est fait dans un tableau

ComboBoxTrie


Private Sub ComboBox1_DropButtonClick()
  Dim temp()
  Set f = Sheets("Feuil1")
  temp = Application.Transpose(f.Range("A2:A" & f.[A65000].End(xlUp).Row))
  Call Tri(temp, LBound(temp), UBound(temp))
  Me.ComboBox1.List = temp
End Sub

Sub Tri(a(), gauc, droi) ' Quick sort
  ref = a((gauc + droi) \ 2)
  g = gauc: d = droi
  Do
    Do While a(g) < ref: g = g + 1: Loop
    Do While ref < a(d): d = d - 1: Loop
    If g <= d Then
       temp = a(g): a(g) = a(d): a(d) = temp
       g = g + 1: d = d - 1
     End If
   Loop While g <= d
   If g < droi Then Call Tri(a, g, droi)
   If gauc < d Then Call Tri(a, gauc, d)
End Sub

Dates

La liste des dates est mise à jour si modification de la liste

Private Sub ComboBox1_DropButtonClick()
  [B2:B1000].Sort key1:=[B2]
  Me.ComboBox1.ListFillRange = "listecombotrié"
End Sub

Private Sub ComboBox1_Change()
   [F1] = CDate(Me.ComboBox1)
   Me.ComboBox1 = Format(CDate(Me.ComboBox1), "dd/mm/yy")
End Sub

ComboBox 2 colonnes

Le menu déroulant est mis à jour dès que la liste en colonne F,G est modifiée.

Créer un nom de champ dynamique:
maliste3 =DECALER($F$2;;;NBVAL($F:$F)-1;2)

Dans les propriétés du comboBox:

ColumnCount
: 2 colonnes
ColumnWidth:40;40

- BOCombo2colonnes -

Private Sub ComboBox1_DropButtonClick()
  ComboBox1.List = Range("maliste3").Value
End Sub

Private Sub ComboBox1_Change()
    MsgBox ComboBox1 & " " & ComboBox1.Column(1)
End Sub

Case à cocher

1- Faire apparaître la boite à outils contrôles(Affichage/Bae outils/Boite à outils contrôles)
2-Dans les propriétés de la case à cocher(clic-droit/propriétés)
-dans la propriété LinkedCell:C4

Groupe d'options

Un groupe d'options

For Each c In ActiveSheet.OLEObjects
   If c.Object.Value And c.Object.GroupName = "CaseOptions" Then
     temp = c.Object.Caption
   End If
Next c
MsgBox temp

Plusieurs groupes d'options

Sub essaiOptions()
  For g = 1 To 4
    MsgBox RéponseOptions("GR" & g)
  Next g
End Sub

Function RéponseOptions(groupe)
   Application.Volatile
   RéponseOptions = ""
   For Each c In ActiveSheet.OLEObjects
     If UCase(c.Object.GroupName) = UCase(groupe) Then
        If c.Object.Value = True Then
          RéponseOptions = c.Object.Caption
        Exit Function
      End If
    End If
  Next c
End Function

CheckBox indicés

Sub Affiche()
For i = 1 To 2
  ActiveSheet.OLEObjects("checkbox" & i).Visible = True
Next i
End Sub

Sub AfficheCache()
  For i = 1 To 2
    ActiveSheet.OLEObjects("checkbox" & i).Visible = Not _
    ActiveSheet.OLEObjects("checkbox" & i).Visible
  Next i
End Sub

Sub CreeCheckBox()
  Set c= ActiveSheet.OLEObjects.Add(ClassType:="Forms.Checkbox.1", Left:=100, Top:=100, Width:=100, Height:=15)
  c.Name = "toto"
End Sub

TYpes d'objet

For Each c In ActiveSheet.OLEObjects
   MsgBox TypeName(c.Object)
Next c

Exemples

Tri avec choix de l'odre de tri dans un comboBox

On choisit la colonne de tri dans un combobox:

Nom de champ dynamique
clétri =DECALER($A$1;;;;NBVAL($1:$1)-1)

Private Sub Workbook_Open()
  Sheets("Tri").ChoixTri.List = Application.Transpose([clétri])
End Sub

Private Sub ChoixTri_Change()
  m = ChoixTri.ListIndex
  Range("A2:D30").Sort Key1:=[A1].Offset(0, m)
End Sub

Choix d'une feuille dans un combo

- Choix Onglet -

Private Sub ChoixOnglet_DropButtonClick()
  Dim temp()
  For i = 1 To Sheets.Count
    ReDim Preserve temp(1 To i)
    temp(i) = Sheets(i).Name
  Next i
  n = UBound(temp)
  Call Tri(temp, 1, n)
  Me.ChoixOnglet.List = temp
End Sub

Private Sub ChoixOnglet_Change()
   m = ChoixOnglet
  Sheets(m).Select
End Sub

Sub Tri(a, gauc, droi) ' Quick sort
  ref = a((gauc + droi) \ 2)
  g = gauc: d = droi
  Do
    Do While a(g) < ref: g = g + 1: Loop
    Do While ref < a(d): d = d - 1: Loop
    If g <= d Then
      temp = a(g): a(g) = a(d): a(d) = temp
      g = g + 1: d = d - 1
    End If
  Loop While g <= d
  If g < droi Then Call Tri(a, g, droi)
  If gauc < d Then Call Tri(a, gauc, d)
End Sub

Positionnement sur un nom

Find44

Private Sub ComboBox1_DropButtonClick()
  ComboBox1.Clear
  For Each c In Range("A6", [A65000].End(xlUp))
    If c <> "" Then ComboBox1.AddItem c
  Next c
End Sub

Private Sub ComboBox1_Change()
    [A:A].Find(what:=ComboBox1).Select
End Sub

Positionnement sur un nom/prénom

Find45

Private Sub ComboBox1_DropButtonClick()
  ComboBox1.Clear
  For Each c In Range("A6", [A65000].End(xlUp))
    If c <> "" Then
      ComboBox1.AddItem
      ComboBox1.List(i, 0) = c & " " & c.Offset(, 1)
      ComboBox1.List(i, 1) = c.Row
      i = i + 1
    End If
  Next c
End Sub

Private Sub ComboBox1_Change()
  On Error Resume Next
  Cells(ComboBox1.Column(1), 1).Select
  'ou Cells(ComboBox1.List(, 1), 1).Select
End Sub

 

 

 


 

 

 

Exemples

BOcontroles
BOFomulaire
BOControlesListBoxTrié
BOcontrolesIndices
Choix onglet combo