nabilexcel2007
XLDnaute Occasionnel
Bonjour j ai un jserform2 avec liistbox1 et textbox2 salaire
Message erreur jaune
Textbox2.value = listbox1.liste(listbox1.listindex, 2) 'salaire
Ma feuille tableaux salaires
A5 date
B5 employe
C5 salaire verser
Private Sub ListBox1_Click()
If ListBox1.ListIndex = -1 Then Exit Sub ' Aucune ligne sélectionnée
' Activer les boutons Modifier et Supprimer si nécessaires
CommandButton2.Enabled = True ' Modifier
CommandButton3.Enabled = True ' Supprimer
' Remplir les champs
TextBox1.Value = ListBox1.List(ListBox1.ListIndex, 0) ' Date
ComboBox1.Value = ListBox1.List(ListBox1.ListIndex, 1) ' Employé
TextBox2.Value = ListBox1.List(ListBox1.ListIndex, 2) ' Salaire
End Sub
Private Sub UserForm_Initialize()
' Charger les employés dans ComboBox1
Dim i As Long
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("liste employé")
ComboBox1.Clear
ComboBox1.AddItem "TOUT" ' Option TOUT
For i = 6 To ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
If ws.Cells(i, 1).Value <> "" Then
ComboBox1.AddItem ws.Cells(i, 1).Value
End If
Next i
' Charger les données dans la ListBox
Call RafraichirListBox
End Sub
Sub RafraichirListBox()
Dim i As Long
Dim derLig As Long
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("tableaux salaires")
With ListBox1
.Clear
.ColumnCount = 3
.ColumnHeads = False ' On ne met pas True si on ne passe pas par RowSource
.ColumnWidths = "100;100;100"
End With
' Déterminer la dernière ligne
derLig = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
If derLig < 6 Then Exit Sub ' Aucune donnée
' Ajouter les données ligne par ligne
For i = 6 To derLig
With ListBox1
.AddItem ws.Cells(i, 1).Value ' Date
.List(.ListCount - 1, 1) = ws.Cells(i, 2).Value ' Employé
.List(.ListCount - 1, 2) = ws.Cells(i, 3).Value ' Salaire
End With
Next i
End Sub
Merci
Message erreur jaune
Textbox2.value = listbox1.liste(listbox1.listindex, 2) 'salaire
Ma feuille tableaux salaires
A5 date
B5 employe
C5 salaire verser
Private Sub ListBox1_Click()
If ListBox1.ListIndex = -1 Then Exit Sub ' Aucune ligne sélectionnée
' Activer les boutons Modifier et Supprimer si nécessaires
CommandButton2.Enabled = True ' Modifier
CommandButton3.Enabled = True ' Supprimer
' Remplir les champs
TextBox1.Value = ListBox1.List(ListBox1.ListIndex, 0) ' Date
ComboBox1.Value = ListBox1.List(ListBox1.ListIndex, 1) ' Employé
TextBox2.Value = ListBox1.List(ListBox1.ListIndex, 2) ' Salaire
End Sub
Private Sub UserForm_Initialize()
' Charger les employés dans ComboBox1
Dim i As Long
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("liste employé")
ComboBox1.Clear
ComboBox1.AddItem "TOUT" ' Option TOUT
For i = 6 To ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
If ws.Cells(i, 1).Value <> "" Then
ComboBox1.AddItem ws.Cells(i, 1).Value
End If
Next i
' Charger les données dans la ListBox
Call RafraichirListBox
End Sub
Sub RafraichirListBox()
Dim i As Long
Dim derLig As Long
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("tableaux salaires")
With ListBox1
.Clear
.ColumnCount = 3
.ColumnHeads = False ' On ne met pas True si on ne passe pas par RowSource
.ColumnWidths = "100;100;100"
End With
' Déterminer la dernière ligne
derLig = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
If derLig < 6 Then Exit Sub ' Aucune donnée
' Ajouter les données ligne par ligne
For i = 6 To derLig
With ListBox1
.AddItem ws.Cells(i, 1).Value ' Date
.List(.ListCount - 1, 1) = ws.Cells(i, 2).Value ' Employé
.List(.ListCount - 1, 2) = ws.Cells(i, 3).Value ' Salaire
End With
Next i
End Sub
Merci