Option Explicit
Option Compare Text
Dim T As ListObject 'Tableau1 ou 2-3-4
Dim TCOL1 As Range
Dim TTITRE As Range 'En tête du Tableau HeaderRowRange.
Dim ligne As Long
Dim i As Byte
Dim Nom As String
Private Sub UserForm_Initialize()
Application.ScreenUpdating = 0
Set T = ActiveSheet.ListObjects(1)
Set TCOL1 = T.DataBodyRange.Columns(1)
Set TTITRE = T.HeaderRowRange
Me.ComboBox1.List = TCOL1.Value
Me.ComboBox2.RowSource = ["Presence_Docs"]
Me.Caption = ActiveSheet.Name & " : " & T.Name
Me.enreg = TCOL1.Rows.Count
Me.Label9.Caption = "VOUS ETES SUR LA FEUILLE ; " & ActiveSheet.Name & " - NOM DU TABLEAU : " & T.Name & vbCrLf & _
Environ("username") & " - " & Environ("computername")
'Caption des Labels en Fonction du Tableau choisi
'Boucle sur les entêtes du Tableau depuis 2 à 7
For i = 1 To 7
Me.Controls("Label" & i) = TTITRE.Columns(i).Text
Next i
Me.Label8.Caption = "Nombre de Item dans : " & T.Name
End Sub
Private Sub ComboBox1_Change()
Nom = Me.ComboBox1.Value
On Error Resume Next
ligne = Application.Match(Nom, TCOL1, 0) 'OK
MsgBox "Ligne " & ligne
On Error GoTo 0
Me.ComboBox2 = ""
For i = 4 To 7
Me.Controls("Textbox" & i - 2) = T.DataBodyRange.Cells(ligne, i).Text
Next i
End Sub
Private Sub ComboBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = 27 Then Unload Me
End Sub
Private Sub CommandButton1_Click()
Nom = Me.ComboBox1.Value
ligne = Application.Match(Nom, TCOL1, 0)
With T.DataBodyRange
.Cells(ligne, 2).Value = Me.ComboBox2
.Cells(ligne, 3).Value = CDate(TextBox1)
.Cells(ligne, 4) = Me.TextBox2
.Cells(ligne, 5) = Me.TextBox3
.Cells(ligne, 6) = Me.TextBox4
.Cells(ligne, 7) = Me.TextBox5
End With
Application.ScreenUpdating = -1
End Sub