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
| Option Explicit
Dim no_section As Integer, del_poste As Integer, no_poste As Integer, i As Integer, colonne As Long, LastLig As Long, c As Range
Private Sub UserForm_Initialize()
colonne = Cells(1 & Columns.Count).End(xlToRight).Column
'Ajout des valeurs des cellules A1 à ... de l'onglet "Sections-Auditeurs-Machines"
For i = 1 To colonne 'Liste des sections
CbB_Section.AddItem Worksheets("Sections-Auditeurs-Machines").Cells(1, i)
Next
End Sub
Private Sub CbB_Section_Change()
'Zone de liste vidée (sinon les valeurs s'ajoutent)
CbB_Suppr_Poste.Clear
'Liste des "section" a sélectionner (ListIndex commence à 0)
no_section = CbB_Section.ListIndex + 1
'Liste des auditeurs de la colonne section choisie
no_poste = Worksheets("Sections-Auditeurs-Machines").Cells(6, no_section).End(xlDown).Row
'Recherche du nombre de lignes poste de la colonne section choisie
For i = 6 To no_poste
CbB_Suppr_Poste.AddItem Worksheets("Sections-Auditeurs-Machines").Cells(i, no_section)
Next
End Sub
Private Sub Supprimer_Click()
Application.ScreenUpdating = False
'Supprime le poste choisi dans la section concernée de l'onglet "Sections-Auditeurs-Machines"
'Activation de la feuille "Sections-Auditeurs-Machines"
Worksheets("Sections-Auditeurs-Machines").Activate
'Détermine la valeur de la sélection (listIndex commence à 6)
del_poste = CbB_Suppr_Poste.ListIndex + 6
'Supprime le poste choisi dans la section concernée de l'onglet "Sections-Auditeurs-Machines
Cells(del_poste, no_section).Delete Shift:=xlUp
'Supprime le poste choisi dans la section concernée de l'onglet "Indicateurs Machines"
'Activation de la feuille "Sections-Auditeurs-Machines"
Worksheets("Indicateurs Machines").Activate
'Copie des lignes à sélectionner dans cellules de destinations
LastLig = Worksheets("Indicateurs Machines").Cells(Rows.Count, 1).End(xlUp).Row
ActiveSheet.Range("$A$1:$E$" & LastLig).AutoFilter Field:=1
For i = 1 To LastLig
Set c = Range("A" & i & ":E" & i).Find(CbB_Suppr_Poste.Value, LookIn:=xlValues, Lookat:=xlWhole)
If Not c Is Nothing Then
c.EntireRow.Delete Shift:=xlUp
Set c = Nothing
End If
Next i
'Affiche le message de réussite
MsgBox "Le poste a été supprimé avec succès!"
Application.ScreenUpdating = True
'Fermer l'USF Formulaire
Unload Me
End Sub
Private Sub Annuler_Click()
Unload Me
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then Cancel = True
End Sub |
Partager