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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
Private Sub userform_initialize()
'Initialisation listbox1
Dim Cell As Range
Dim Unique As New Collection
Dim Valeur As Range
Dim i As Integer
ListBox1.ColumnCount = 2
On Error Resume Next
For Each Cell In Range("Pen_Postes")
Unique.Add Cell, CStr(Cell)
Next Cell
On Error GoTo 0
For Each Valeur In Unique
Me.ListBox1.AddItem Valeur
Next Valeur
For i = 0 To ListBox1.ListCount - 1
ListBox1.List(i, 1) = Range("Pen_Pen").Cells(i + 1, 1)
Next i
'----------------------
Private Sub CommandButton1_Click()
réponse = MsgBox("Es tu sûr(e) de vouloir supprimer ce poste?", vbYesNo + vbExclamation)
If réponse = vbNo Then Exit Sub
Range("Pen_Postes").Cells(Me.ListBox1.ListIndex + 1, 1).EntireRow.delete shift:=xlUp
With Sheets("Description Poste")
.AutoFilterMode = False
.Range("B2:D2").AutoFilter
.AutoFilter.Sort.SortFields.Clear
.AutoFilter.Sort.SortFields.Add Key:=Range("B2"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
End With
With ActiveWorkbook.Worksheets("Description Poste").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Private Sub CommandButton2_Click()
If TextBox1.Value = "" Or TextBox2.Value = "" Then
MsgBox "Merci de définir correctement le poste", vbInformation + vbOKOnly
Exit Sub
End If
If Not IsNumeric(TextBox2.Value) Or TextBox2.Value > 4 Or TextBox2.Value < 1 Then
MsgBox "La pénibilité doit être un chiffre compris entre 1 et 4. La valeur 0 correspond à une pause", vbInformation + vbOKOnly
Exit Sub
End If
Range("Pen_Postes").Cells(Me.ListBox1.ListIndex + 1, 1) = TextBox1.Value
Range("Pen_Pen").Cells(Me.ListBox1.ListIndex + 1, 1) = TextBox2.Value
Range("Pen_Com").Cells(Me.ListBox1.ListIndex + 1, 1) = TextBox3.Value
With Sheets("Description Poste")
.AutoFilterMode = False
.Range("B2:D2").AutoFilter
.AutoFilter.Sort.SortFields.Clear
.AutoFilter.Sort.SortFields.Add Key:=Range("B2"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
End With
With ActiveWorkbook.Worksheets("Description Poste").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Private Sub CommandButton3_Click()
If Not IsNumeric(TextBox2.Value) Or TextBox2.Value > 4 Or TextBox2.Value < 1 Then
MsgBox "La pénibilité doit être un chiffre compris entre 1 et 4. La valeur 0 correspond à une pause", vbInformation + vbOKOnly
Exit Sub
End If
If TextBox1.Value = "" Or TextBox2.Value = "" Then
MsgBox "Merci de définir correctement le poste", vbInformation + vbOKOnly
Exit Sub
End If
n = Application.WorksheetFunction.CountA(Range("Pen_Postes"))
Range("Pen_Postes").Cells(n + 1, 1) = TextBox1.Value
Range("Pen_Pen").Cells(n + 1, 1) = TextBox2.Value
Range("Pen_Com").Cells(n + 1, 1) = TextBox3.Value
With Sheets("Description Poste")
.AutoFilterMode = False
.Range("B2:D2").AutoFilter
.AutoFilter.Sort.SortFields.Clear
.AutoFilter.Sort.SortFields.Add Key:=Range("B2"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
End With
With ActiveWorkbook.Worksheets("Description Poste").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Private Sub ListBox1_Click()
If Me.ListBox1.ListIndex < 0 Then
MsgBox "Aucun poste n'est sélectionné", vbOKOnly + vbInformation
Exit Sub
End If
TextBox1.Value = Range("Pen_Postes").Cells(Me.ListBox1.ListIndex + 1, 1)
TextBox2.Value = Range("Pen_Pen").Cells(Me.ListBox1.ListIndex + 1, 1)
TextBox3.Value = Range("Pen_Com").Cells(Me.ListBox1.ListIndex + 1, 1)
End Sub
End Sub |
Partager