LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Count File Names


See if this code works. I assume that 2010-01 is year and month.


Sub GetLatestFile()


Folder = "c:\temp\"

LatestDate = 0
LatestVersion = 0
LatestFName = ""

'make sure folder name has last backslash
If Right(Folder, 1) < "\" Then
Folder = Folder & "\"
End If

CountYear = 0
FName = Dir(Folder & "*.xls")
Do While FName < ""
'split file name into two piece around the space
NewVersionArray = Split(FName, " ")
'spit the date portion of the file name into year and month
NewDateArray = Split(Trim(NewVersionArray(0)), "-")
'convert the date to a number (serial date), use the first day of
the month
NewDate = DateSerial(NewDateArray(0), NewDateArray(1), 1)

'count if file is this year
If Year(NewDate) = 2010 Then
CountYear = CountYear + 1
End If

'remove the V from verion so version is a number
NewVersion = Val(Mid(Trim(NewVersionArray(1)), 2))

If NewDate LatestDate And _
NewVersion LatestVersion Then

LatestDate = NewDate
LatestVersion = NewVersion
LatestFName = FName
End If

FName = Dir()
Loop

'add folder name to latest file name
LatestFName = Folder & LatestFName


End Sub


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=169466

Microsoft Office Help

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count Names NOT #N/A Dax Arroway Excel Worksheet Functions 3 May 12th 23 07:44 PM
Match file names listed in column with file names in folder K[_2_] Excel Programming 1 March 16th 09 04:26 PM
Count Names relo Excel Worksheet Functions 7 August 8th 07 07:42 PM
Count Names mudraker Excel Worksheet Functions 2 June 22nd 06 09:21 AM
Count Names Diana Excel Discussion (Misc queries) 3 September 22nd 05 06:00 PM


All times are GMT +1. The time now is 03:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"