Sub Ma_date_New()
Call Connexion_Pe("xx", "xx", "xx")
Dim Sel_Pol As String
Nl = 3 ' nombre de lignes (polices) à prendre en compte
Nr = 2 ' numéro de ligne de début de données
For Each Cel In Application.Transpose(Cells(Nr, "A").Resize(Nl))
Sel_Pol = IIf(Sel_Pol = "", "'", Sel_Pol & ",'") & Cel & "'"
Next
Dim RECSET As Object
Set RECSET = CreateObject("ADODB.recordset")
RECSET.Open _
" select sousc.no_police as no_police " & _
" from dossier sousc,contractant cntr, personne pers " & _
" where sousc.is_contractant = cntr.is_contractant " & _
" and pers.is_personne = cntr.is_personne " & _
" and sousc.no_police in (" & Sel_Pol & ")", _
cnn_Pe, adOpenDynamic, adLockBatchOptimistic
If Not RECSET.EOF Then
Cells(Nr, "C").CopyFromRecordset RECSET
With Cells(Nr, "D").Resize(RECSET.RecordCount)
.FormulaR1C1 = "=IF(RC[-1]="""","""",DATEDIF(RC[-1],TODAY(),""y""))"
.NumberFormat = "General"
End With
Else
MsgBox "Pas d'enregistrements correspondants à" & vbLf & Sel_Pol
End If
RECSET.Close
Set RECSET = Nothing
Call Deconnexion_Pe
End Sub