This is for an Excel worksheet. Data is entered or modified in column A. The macro automatically enters the date/time in column B. The macro then sorts column A & B by column B, putting the most recent at the top.
Enter the following event macro in the worksheet code area:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim A As Range
Dim AB As Range
Set A = Range("A:A")
Set AB = Range("A:B")
If Intersect(Target, A) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
Application.EnableEvents = False
Target.Offset(0, 1) = Now
AB.Sort Key1:=Range("B1"), Order1:=xlDescending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Application.EnableEvents = True
End Sub
Because it is worksheet code, it is very easy to install and automatic to use:
- right-click the tab name near the bottom of the Excel window
- select View Code - this brings up a VBE window
- paste the stuff in and close the VBE window
If you have any concerns, first try it on a trial worksheet.
If you save the workbook, the macro will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the macro:
- bring up the VBE windows as above
- clear the code out
- close the VBE window
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
Macros must be enabled for this to work!
Many questions, so I'm going to answer the "how does it work" part, not "how do I get this working."
This is dependent on the file system used. I'm answering based on ext[234], others probably work the same way or similarly.
No, the directory modification time doesn't change if a file is modified. The directory is not modified in this case in any way, it still contains the same files, directories etc linked to it.
The same as previous, if "changing a file" means the same as "modifying some file."
If you remove a file and add a new one with the same name, or move another file "on top" of another, then the directory is modified.
When the directory is modified. This means linking/unlinking inodes into it, like files or subdirectories.
Permission changes alter the change time, but not modification time. These are different.
If you move the directory elsewhere, the change time will change, but modification time won't.
Directory access time is changed when the directory is accessed, if it hasn't been turned off. The volume might be mounted with noatime which means no last access time is written usually. Note that directory data is also cached.
Also if you just access a subdirectory, the access time on the parent(s) doesn't change.
So if you search for directories not changed in the past 300 days, they might still contain files that have changed. File creation or removal hasn't happened, but editing contents may have. You will have to check by files as you said.
Best Answer
It is
for the files not modified in this period (
-150
will list the modified files).