run time error 53
Am I correct in assuming that where you have For Count = 1 to 1 that you have
substituted this when trying to test your code and it should actually be as
follows
For Count = 1 to Counter
If so then edit the following code as per the comments because with your
method Count will finish up 1 greater than the number of files because it
gets 1 added to it after being used in the last valid loop. The following
method only adds 1 for each valid loop.
counter = 0 'Initialize to zero instead of 1
For Each fc In myfiles
counter = counter + 1 'set counter before using its value
tmp.Sheets(1).Cells(counter, 1).Value = fc.Name
tmp.Sheets(1).Cells(counter, 2).Value = fc.datelastmodified
'counter = counter + 1 'Remove this line
Next
tmp.Sheets(1).Columns("B:B").EntireColumn.AutoFit
tmp.Sheets(1).Range(Selection, Selection.End(xlToRight)).Select
tmp.Sheets(1).Range(Selection, Selection.End(xlDown)).Select
Set sortrange = Selection
For Count = 1 To Counter
--
Regards,
OssieMac
|