Private Sub CommandButton2_Click()
[COLOR="Red"]Dim Ligne As Long
Ligne = Range("A65536").End(xlUp).Row + 1[/COLOR]
[COLOR="DarkOliveGreen"]If Application.CountA(Feuil1.[A3:B40]) > 0 Then Feuil1.[A3:B0].ClearContents[/COLOR]
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DRIVER={Microsoft ODBC for Oracle};UID=dept_85;PWD=dept_85;SERVER=producim;", _
Destination:=Range("A3"))
.CommandText = Array( _
"SELECT histo_tr.DT_DEB_CONS as Date_Heure, Sum(histo_event_tr.QTE_PROD)as Quantité" & Chr(13) & "" & Chr(10) & "FROM DEPT_85.histo_event_tr histo_event_tr, DEPT_85.histo_tr histo_tr" & Chr(13) & "" & Chr(10) & "WHERE histo_event_tr.ID_HISTO = histo_tr.ID_HISTO AND ((histo_event_tr" _
, _
".ID_RESS_HISTO='UPAV3_CU11_0') AND (histo_tr.DT_DEB_CONS>to_date(concat(to_char(sysdate,'yymmdd'),'0530'),'yymmddhh24mi')) OR (histo_event_tr.ID_RESS_HISTO='UPAV3_CU12_0') AND (histo_tr.DT_DEB_CONS>to" _
, _
"_date(concat(to_char(sysdate,'yymmdd'),'0530'),'yymmddhh24mi')) OR (histo_event_tr.ID_RESS_HISTO='UPAV3_CU21_0') AND (histo_tr.DT_DEB_CONS>to_date(concat(to_char(sysdate,'yymmdd'),'0530'),'yymmddhh24m" _
, _
"i')) OR (histo_event_tr.ID_RESS_HISTO='UPAV3_CU22_0') AND (histo_tr.DT_DEB_CONS>to_date(concat(to_char(sysdate,'yymmdd'),'0530'),'yymmddhh24mi')))" & Chr(13) & "" & Chr(10) & "GROUP BY histo_tr.DT_DEB_CONS" _
)
.Name = "Production_Equipe1"
.FieldNames = False
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 2
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub