If .Range("A" & i).Value = ladate Then
Sub importer() Dim classeurSource As Workbook, classeurDestination As Workbook 'ouvrir le classeur source (en lecture seule) Set classeurSource = Application.Workbooks.Open("C:\donnees\source.xlsx", , True) 'définir le classeur destination Set classeurDestination = ThisWorkbook 'copier les données de la "Feuil1" du classeur source vers la "Feuil1" du classeur destination classeurSource.Sheets("liste").Cells.Copy classeurDestination.Sheets("resultat").Range("A1") 'fermer le classeur source classeurSource.Close False End Sub
Sub Macro1() Dim a As Variant, Nom As String Nom = ActiveWorkbook.Name ChDrive "C:" ' Choix du lecteur ChDir "C:" 'Choix du répertoire a = Application.GetOpenFilename("fichier excel (*.xlsx), *.xlsx", _ , "source", , True) Select Case TypeName(a) Case Is = "Boolean" Exit Sub Case Else For b = LBound(a) To UBound(a) Workbooks.Open a(b) Next End Select Nom2 = ActiveWorkbook.Name Cells.Select Selection.Copy Windows(Nom).Activate Range("A1").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.DisplayAlerts = False Windows(Nom2).Close Application.DisplayAlerts = True End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionDim ladate As Date, plage As Range ladate Date - 7 ' qui pourrait s'écrire ladate DateAdd("d", -7, Date) With Sheets("Feuil1") For i = 2 To .Range("A" & Rows.Count).End(xlUp).Row If .Range("A" & i).Value = ladate Then If plage Is Nothing Then Set plage = .Range("A" & i & ":" & "E" & i) Else Set plage = Union(plage, .Range("A" & i & ":" & "E" & i)) End If End If Next End With Sheets("Feuil2").Cells.ClearContents If Not plage Is Nothing Then plage.Copy Destination:=Sheets("Feuil2").Range("A1") End If
Dim ladate As Date, plage As Range ladate = Date - 7 With Sheets("Feuil1") Set plage = .Range("A1:E1") ' ---- dobnc plage ne sera jamais Nothing, hein ... For i = 2 To .Range("A" & Rows.Count).End(xlUp).Row If .Range("A" & i).Value = ladate Then Set plage = Union(plage, .Range("A" & i & ":" & "E" & i)) End If Next End With Sheets("Feuil2").Cells.ClearContents plage.Copy Destination:=Sheets("Feuil2").Range("A1")
Sub imp() Dim ladate As Date, plage As Range ladate = DateDiff("d", Date, Date - 7) With Workbooks("C:\donnees\source.xlsx").Sheets("liste") For i = 2 To .Range("A" & Rows.Count).End(xlUp).Row If .Range("A" & i).Value = ladate Then If plage Is Nothing Then Set plage = .Range("A" & i & ":" & "E" & i) Else Set plage = Union(plage, .Range("A" & i & ":" & "E" & i)) End If End If Next End With Workbooks("sortie.xlsm").Sheets("resultat").Cells.ClearContents If Not plage Is Nothing Then plage.Copy Destination:=Workbooks("sortie.xlsm").Sheets("resultat").Range("A1") End If End Sub
Sub choixdudossier() Dim Fichier_Travail As String If Not Application.Dialogs(xlDialogOpen).Show Then Exit Sub 'On ouvre la fenêtre Windows pour choisir le fichier Fichier_Travail = ActiveWorkbook.Name 'Met dans une variable le nom du fichier End Sub
Sub Import() Set Destination = ActiveWorkbook Dim ladate As Date, Plage As Range ladate = DateAdd("d", -7, Date) Source = Application.Dialogs(xlDialogOpen).Show If Source = False Then MsgBox ("Aucun fichier sélectionné") Exit Sub Else Set Source = ActiveWorkbook Source.Activate Sheets(1).Select For I = 2 To .Range("A" & Rows.Count).End(xlUp).Row If .Range("A" & I).Value = ladate Then If Plage Is Nothing Then Set Plage = .Range("A" & I & ":" & "E" & I) Else Set Plage = Union(Plage, .Range("A" & I & ":" & "E" & I)) End If End If Next Plage.Select Selection.Copy Destination.Activate Sheets(2).Select Range("A1").Select Selection.PasteSpecial Paste:=xlPasteValues Source.Activate Application.CutCopyMode = False ActiveWindow.Close SaveChanges:=False End If End Sub
For I = 2 To .Range("A" & Rows.Count).End(xlUp).Row
Sub Import() Set Destination = ActiveWorkbook Dim ladate As Date, Plage As Range ladate = DateAdd("d", -7, Date) Source = Application.Dialogs(xlDialogOpen).Show If Source = False Then MsgBox ("Aucun fichier sélectionné") Exit Sub Else Set Source = ActiveWorkbook Source.Activate Sheets(1).Select For I = 2 To Worksheets("liste").Range("A" & Rows.Count).End(xlUp).Row If Worksheets("liste").Range("A" & I).Value = ladate Then If Plage Is Nothing Then Set Plage = Worksheets("liste").Range("A" & I & ":" & "E" & I) Else Set Plage = Union(Plage, Worksheets("liste").Range("A" & I & ":" & "E" & I)) End If End If Next Plage.Select Selection.Copy Destination.Activate Sheets(2).Select Range("A1").Select Selection.PasteSpecial Paste:=xlPasteValues Source.Activate Application.CutCopyMode = False ActiveWindow.Close SaveChanges:=False End If End Sub
Destination.Activate