1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
Option Explicit
Dim interne As Boolean
Sub LbxFormation_Change()
Dim ch As String, i As Long, sep As String
If Not interne Then
ch = ""
sep = ", "
For i = 0 To lbxFormation.ListCount - 1
If lbxFormation.Selected(i) = True Then ch = ch & sep & lbxFormation.List(i)
Next i
ch = Mid(ch, Len(sep) + 1)
ActiveCell = ch
End If
End Sub
Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim ch As String, ch2 As String, pos As Long, i As Long
Dim plage, nomListe, numListe As Long, topIndex As Boolean
' plages avec sélection multiple sur cette feuille
plage = Array("lstSouhaits")
' nom des liste dans la feuille liste (en liaison avec les plages définies au-dessus)
nomListe = Array("lstFormation")
' plage concernée ?
For numListe = 0 To UBound(plage)
If Not Intersect(Target, Range(plage(numListe))) Is Nothing Then Exit For
Next numListe
If numListe <= UBound(plage) Then ' si plage de liste existant
' initialiser listbox
lbxFormation.ListFillRange = "BDD Formations!" & Worksheets("BDD Formations").Range(nomListe(numListe)).Address
lbxFormation.Top = Target.Offset(1, 0).Top
lbxFormation.Left = Target.Offset(0, 1).Left
interne = True
ch = ActiveCell
ch2 = ", " & ch & ", "
topIndex = False
' sélectionner selon contenu cellule
For i = 0 To lbxFormation.ListCount - 1
If InStr(ch2, ", " & lbxFormation.List(i) & ", ") > 0 Then
' l'item a été trouvé dans la cellule
lbxFormation.Selected(i) = True
If Not topIndex Then
lbxFormation.topIndex = i ' le 1er sélectionné doit être visible dans la textbox
topIndex = True
End If
End If
Next i
interne = False
' afficher textbox
lbxFormation.Visible = True
Else
' ne plus afficher la textbox
lbxFormation.Visible = False
End If
End Sub
Sub reinit()
Application.EnableEvents = True
End Sub |
Partager