Forum Discussion
Colin Lim
Mar 13, 2018Copper Contributor
Extract Data from All Files w/ a Last Modified Date Between 02/01/2018 and 02/24/2018
Hi Everyone,
I have a folder with Excel files that are completely standardized in terms of the type of data in specific cells. What I am hoping to be able to do is to have the VBA code only ret...
Matt Mickle
Mar 13, 2018Bronze Contributor
Try editing your code to look like this....
Please note you need to adjust the lines that say "YOUR DATE HERE":
Public Sub GetFiles()
On Error GoTo exitloop
Path = "D:\Report Data\Berries\"
' Start Loop Function
NextFile = Dir(fpath & "*.xls*")
Do While NextFile <> ""
myModifyDate = FileLastModified(Path & NextFile)
If myModifyDate > "YOUR DATE HERE" And myModifyDate < "YOUR DATE HERE" Then
' Open WorkBook
Workbooks.Open Filename:=Path & NextFile
' Copy/Paste Data from File/WorkBook
Call ExtractData
' Close WorkBook and Suppress Saving Request2
ActiveWorkbook.Close False
End If
NextFile = Dir
Loop
exitloop:
End Sub
Private Sub ExtractData()
' Specify WorkSheet name below in quotes
TargetSh = "Berries Composite Data"
With ThisWorkbook.Sheets(TargetSh)
' Places Curser in Last Row
NxtEmptyRw = .Cells(65536, 1).End(xlUp).Row + 1
' Be sure to place number after the comma of NxEmptyRw serially and sequentially so as not to override data.
.Cells(NxtEmptyRw, 1).Value = ActiveWorkbook.Worksheet("Phase01").Range("C6").Value
.Cells(NxtEmptyRw, 2).Value = ActiveWorkbook.Worksheet("Phase01").Range("C8").Value
.Cells(NxtEmptyRw, 3).Value = ActiveWorkbook.Worksheet("Phase01").Range("W7").Value
.Cells(NxtEmptyRw, 4).Value = ActiveWorkbook.Worksheet("Phase01").Range("W3").Value
.Cells(NxtEmptyRw, 5).Value = ActiveWorkbook.Worksheet("Phase01").Range("Y4").Value
End With
End Sub
Function FileLastModified(strFullFileName As String)
Dim fs As Object, f As Object, s As String
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(strFullFileName)
s = f.DateLastModified
FileLastModified = s
Set fs = Nothing: Set f = Nothing
End Function