Sub Gr_CP()
'extraire 1 groupe de CP
[COLOR="Red"][B]GrCp = InputBox([/B][COLOR="Blue"]"Entrez le groupe de CP","Congés Payés","saisir un nombre entier entre 1 et 30"[/COLOR][B])[/B]
[COLOR="Green"]' Test s'il s'agit d'un nombre[/COLOR]
[B]If Not Isnumeric(GrCp) Then
MsgBox "Veuillez saisir une valeur numérique, SVP", vbOkOnly + vbExclamation, "Erreur"
Exit Sub
End If[/B][/COLOR]
[COLOR="Green"]' Test s'il s'agit d'un nombre entier[/COLOR]
[COLOR="Blue"]If CLng(Grcp) <> CDbl(Grcp) Then
MsgBox "Veuillez saisir un nombre entier, SVP", vbOKOnly + vbExclamation, "Erreur"
Exit Sub
End If[/COLOR]
[COLOR="Green"]' Test s'il s'agit d'un nombre compris entre 1 et 30[/COLOR]
[COLOR="Blue"]If Grcp < 1 Or Grcp > 30 Then
MsgBox "Veuillez saisir un nombre entier compris entre 1 et 30, SVP", vbOKOnly + vbExclamation, "Erreur"
Exit Sub
End If[/COLOR]
Sheets("Plan N").Unprotect "toto"
Dim plage As Range, c As Range, cSource As Range
Set plage = Feuil1.Range("B1:O55") 'zones selection pour transfert macro
Application.ScreenUpdating = False
For Each c In plage
If Not IsEmpty(c) Then
Set cSource = Sheets("BD").UsedRange.Find(what:=c, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False)
If Not cSource Is Nothing Then
If cSource.Offset(0, 4).Value = [COLOR="Red"][B]GrCp[/B][/COLOR] Then
c.Copy Destination:=Sheets("Plan N").Range("U" & _
Application.Rows.Count).End(xlUp)(2)
c.Clear 'Nettoie la cellule, contenu et format.
c.Locked = False
End If
End If
End If
Next c
'plage.Locked = False
Application.ScreenUpdating = True
Sheets("Plan N").Protect "toto", AllowFormattingCells:=True
End Sub