Sub Test()
Dim T1 As String, T2 As String, P1 As String, P2 As String
With ThisWorkbook.Sheets("Feuil1")
P1 = "SELECT * from [Feuil1$" & Replace(.Range(.Range("A1"), .Cells(.Cells.Rows.Count, "E").End(xlUp)).Address, "$", "") & "]"
P2 = "SELECT * FROM [Feuil1$" & Replace(.Range(.Range("G1"), .Cells(.Cells.Rows.Count, "K").End(xlUp)).Address, "$", "") & "]"
Dim SQL1 As String, SQL2 As String
SQL1 = P1 & " as FRM1 left join (" & P2 & ") as FRM2 on FRM2.CODE=FRM1.CODE and FRM2.Statut=FRM1.Statut and FRM2.Age=FRM1.Age and FRM2.sexe=FRM1.sexe and FRM2.ttt=FRM1.ttt"
SQL1 = SQL1 & " WHERE FRM2.CODE is null"
SQL2 = P2 & " as FRM1 left join (" & P1 & ") as FRM2 on FRM2.CODE=FRM1.CODE and FRM2.Statut=FRM1.Statut and FRM2.Age=FRM1.Age and FRM2.sexe=FRM1.sexe and FRM2.ttt=FRM1.ttt"
SQL2 = SQL2 & " WHERE FRM2.CODE is null"
End With
With CreateObject("AdoDb.Connection")
.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.FullName & ";Extended Properties=""Excel 12.0;HDR=YES;"""
With .Execute(SQL1)
T1 = .GetString(, , vbTab, vbCrLf, "")
.Close
End With
With .Execute(SQL2)
T2 = .GetString(, , vbTab, vbCrLf, "")
.Close
End With
.Close
End With
With Sheets("Feuil1")
With .UsedRange
Range(.Range("A2"), .Cells(.Rows.Count, .Columns.Count)).Clear
End With
PressePapier = T1: .Range("A2").PasteSpecial xlPasteAll
PressePapier = T2: .Range("G2").PasteSpecial xlPasteAll
ClearCipboard
End With
End Sub
Public Property Let PressePapier(Value)
With CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
.SetText Value
.PutInClipboard
End With
End Property
Public Property Get PressePapier()
With CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
.GetFromClipboard
PressePapier = .GetText
End With
End Property
Function ClearCipboard()
'Early binding will requires a Reference to 'Microsoft Forms 2.0 Object Library'
Dim oData As Object 'New MSForms.DataObject
Set oData = CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
oData.SetText Text:=Empty
oData.PutInClipboard
Set oData = Nothing
End Function