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
| Function ConcatVlookUp_RS(ByVal ValRecherche As Range, _
ByVal Table As Range, _
ByVal IndexColSearch As Integer, _
ByVal IndexColResult As Integer, _
Optional ByVal blnConcat As Boolean = False, _
Optional ByVal separateur = ";") As Variant
Dim t0 As Single
t0 = Timer
Dim dbEng As Object
Dim db As Object
Dim rs As Object
Dim sql As String
Set dbEng = CreateObject("DAO.DBEngine.36")
Set db = dbEng.Workspaces(0).OpenDatabase(ValRecherche.Parent.Parent.FullName, False, False, "Excel 8.0;HDR=NO;")
sql = "SELECT [F" & IndexColResult & "] FROM [" & Table.Parent.Name & "$" & Table.Address(False, False, xlA1) & "] " & _
"WHERE [F" & IndexColSearch & "] Like '" & ValRecherche.Value & "'"
Set rs = db.openrecordset(sql, 4)
rs.movefirst
Do While Not (rs.EOF)
ConcatVlookUp_RS = ConcatVlookUp_RS & separateur & rs.fields(0).Value
rs.movenext
Loop
rs.Close
ConcatVlookUp_RS = Mid(ConcatVlookUp_RS, Len(separateur) + 1)
Set rs = Nothing
Set db = Nothing
Set dbEng = Nothing
Debug.Print "RS - " & Timer - t0; ""
End Function |
Partager