Private Sub BoutValidAjout_Click()
Dim Ligne As Range
Application.ScreenUpdating = False
If Me.TextNOM.Value = "" Then
MsgBox "Vous devez obligatoirement saisir un NOM."
Exit Sub
End If
Sheets("Accès").Visible = True
If MsgBox("Confirmez-vous les droits pour cet(te) employé(e) ?", vbYesNo, "Demande de confirmation de création") = vbYes Then
If CBool(NomPnom(CStr(Me.TextNOM.Value), CStr(Me.TextPrenom.Value), ThisWorkbook.Sheets("Accès").Range("A:A"))) Then
' Not ThisWorkbook.Sheets("Accès").Range("A:A").Find(CStr(Me.TextNOM.Value), LookIn:=xlValues) Is Nothing Then
MsgBox Me.TextNOM.Value & " " & Me.TextPrenom.Value & " Existe déja", vbExclamation
Exit Sub
End If
With Sheets("Accès").ListObjects(1)
If .InsertRowRange Is Nothing Then
Set Ligne = .ListRows.Add().Range
Ligne(1, 1).Value = Me.TextNOM.Value
Ligne(1, 2).Value = Me.TextPrenom.Value
Ligne(1, 3).Value = Me.TextMdP.Value
Ligne(1, 4).Value = "X"
Set Ligne = Nothing
End If
Worksheets("Accès").Range("A:L").Columns.AutoFit
End With
End If
Application.ScreenUpdating = True
End Sub
"***********************************************************************************************************
' fonction recherche de doublons!
'-----------------------------------------------------------------------------------------------------------
Function NomPnom(Nom As String, Prenom As String, Plage As Range, Optional Appre As String = "A1") As Integer
Dim r As Range, Pos As Integer
Set r = Plage.Find(Nom, After:=Range(Appre), LookIn:=xlValues)
If Not r Is Nothing Then
If Range(Appre).Row > r.Row Then NomPnom = 0: Exit Function
If r.Offset(, 1) <> Prenom Then NomPnom = NomPnom(Nom, Prenom, Plage, r.Address) Else NomPnom = r.Row
Else
NomPnom = 0
End If
End Function
"***********************************************************************************************************