ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sorting dates (https://www.excelbanter.com/excel-programming/425983-re-sorting-dates.html)

Bernie Deitrick

Sorting dates
 
Eli,

Your code works fine, but you may have not seen anything because you increment your row counter
whether or not the file meets your requirement, so change

End If
r = r + 1 ' next row number

to

r = r + 1 ' next row number
End If

HTH,
Bernie
MS Excel MVP


"???" wrote in message
...
Hi!

I have found a function that imports a list of file names with its last
modification date (www.exceltip.com) and I have modified it so only files
with *.res extention will be imported. I want also to import only files that
was modified in the last 2 days but it not worked (see the code below). the
date is in the format of: dd/mm/yyyy hh:mm.

Sub ListFilesInFolder(SourceFolderName As String, IncludeSubfolders As
Boolean)
Dim FSO As Scripting.FileSystemObject
Dim SourceFolder As Scripting.Folder, SubFolder As Scripting.Folder
Dim FileItem As Scripting.File
Dim r As Long
Dim t As Long
Dim s As Date
Set FSO = New Scripting.FileSystemObject
Set SourceFolder = FSO.GetFolder(SourceFolderName)
s = Now()
r = Range("A65536").End(xlUp).Row + 1
For Each FileItem In SourceFolder.Files
t = s - FileItem.DateLastModified
If Right(FileItem.Name, 3) = "res" And t < 2 Then
Cells(r, 1).Formula = FileItem.Name
Cells(r, 2).Formula = FileItem.DateLastModified
End If
r = r + 1 ' next row number
Next FileItem
Columns("A:B").AutoFit
Set FileItem = Nothing
Set SourceFolder = Nothing
Set FSO = Nothing
ActiveWorkbook.Saved = True
End Sub

I will be happy to understand what is wrong with it.

Thanks in advance

Eli





All times are GMT +1. The time now is 08:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com