Sub Remplissageligne()
Dim w1 As String
Dim nom_soignant As String
Dim cellule As Range, plage As Range
Dim d As Range
Dim col As Byte
Dim lig As Long
Dim val1 As Variant
col = 3 ' première colonne
w1 = ActiveSheet.Name
nom_soignant = ActiveCell.Value
If nom_soignant = "" Then
Call MsgBox("Vous n'apez pas sélectionné un soignant", vbInformation, Application.Name)
Exit Sub
End If
With Worksheets("Base_Soignants")
dl1 = .Range("a65536").End(xlUp).Row + 2
Set plage = .Range("a8:a" & .Range("a65536").End(xlUp).Row)
End With
For Each cellule In plage
If cellule.Value = nom_soignant Then Exit For
Next cellule
lig = cellule.Row
With Sheets(w1)
Set plage = .Range("c9:ag9")
For Each cellule In plage
val1 = recherche("Base_Soignants", CStr(cellule.Value), CStr(cellule.Offset(2, 0).Value), lig)
.Cells(ActiveCell.Row, cellule.Column) = val1
Next cellule
End With
Worksheets(w1).Activate
End Sub
Private Function recherche(£feul As String, £val1 As String, £val2 As String, £lig As Long)
Dim £plage As Range
Dim £cellule As Range
With Sheets(£feul)
recherche = ""
Set £plage = .Range("f1:ag1")
For Each cellule In £plage
If CStr(cellule.Value) = £val1 And LCase(CStr(cellule.Offset(1, 0).MergeArea(1))) = £val2 Then
recherche = cellule.Offset(£lig - 1, 0).Value
Exit Function
End If
Next cellule
End With
End Function