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 64 65
| Option Explicit
'mes variables "Public"
Public TbListbox(), x As Integer, Nligne As Long, Liste(), Lt(), y As Integer
Public matricule As String
Sub ini_T()
Dim Ctrl As Control 'pour boucler sur controles
x = 0: y = 0
For Each Ctrl In UserForm_Modif.Controls 'la boucle sur les contrôles
'verifie s'il s'agit d'un textbox
If TypeOf Ctrl Is MSForms.TextBox Then
y = y + 1: ReDim Preserve Lt(1 To y): Lt(y) = Ctrl.Name 'j'alimente un nouveau tableau avec _
le nom des textbox
x = x + 1
End If
Next Ctrl
End Sub
Sub Change_consult()
Dim entete
entete = Array(9, 10, 11, 8) 'ce tableau reprend les numéros de colonne concernées par les textbox
y = 3
For x = 1 To UBound(Lt) 'je boucle sur ce tableau
'ci-dessous Nligne est le numéro de ligne, entete(y) le numéro de colonne
Sheets("consultation").Cells(Nligne, entete(y)) = UserForm_Modif.Controls(Lt(x)) 'Lt(x)représentant le contenu du textbox
y = y - 1
Next
Consultation.ListBox_MedTrav.Clear 'je vide la listbox mais tu pourras modifier
remplir 'je vais dans la procédure
End Sub
Sub remplir() 'la procédure qui remplit la listbox
Dim Plage As Range, Cell As Range
Dim Recherche As String, Adresse As String
Dim Ligne As Integer, n As Integer
Dim c As Range, j As Range
Consultation.ListBox_MedTrav.Clear
n = 0
With Sheets("consultation")
Recherche = Consultation.TextBox_matricule.Value
Ligne = .Range("D" & .Rows.Count).End(xlUp).Row
Set Plage = .Range("D1", "E" & Ligne)
End With
With Plage
Set j = .Find(Recherche, , xlValues)
'ci-dessous je te l'ai laissé
If Not j Is Nothing Then
Adresse = j.Address
Do
If UCase(Recherche) = UCase(Left(j, Len(Recherche))) Then
With Consultation
.ListBox_MedTrav.AddItem j.Offset(0, -1), n
.ListBox_MedTrav.List(n, 1) = j.Offset(0, 5)
.ListBox_MedTrav.List(n, 2) = j.Offset(0, 6)
.ListBox_MedTrav.List(n, 3) = j.Offset(0, 7)
.ListBox_MedTrav.List(n, 4) = j.Offset(0, 4)
.ListBox_MedTrav.List(n, 5) = j.Offset(0, 4).Row
n = n + 1
End With
End If
Set j = .FindNext(j)
Loop While Not j Is Nothing And j.Address <> Adresse
End If
End With
End Sub |