Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 30
Default Finding a folder with the largest number.

Hello
Is it possible to search through a set of folders or directories and choose
the one with the largest number? Excel has a MAX function for finding the
largest number on a ss which I need to use later but I have to find a dir
with the largest number which in turn is the newest date. It's an odd date
format.

thanks for any help
Steve
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default Finding a folder with the largest number.

You can use code like the following. Change the line marked with '<<<
to the start folder name, which contains all the subfolders whose
dates are to be compared. Since you don't specify how the folder names
translate to numbers, I've left that function empty. In the
DateFromFolderName function, put in whatever code you need to get the
appropriate value from the String variable FolderName. This variable
will contain the unqualified name (no path information) of the folder
passsed to it.

You'll need a reference to the Scripting runtime. In VBA, go to the
Tools menu, choose References, and scroll down to and check the entry
for "Microsoft Scripting RunTime".

Sub AAA()
Dim FSO As Scripting.FileSystemObject
Dim SubF As Scripting.Folder
Dim StartFolderName As String
Dim LatestDate As Long
Dim LatestFolderName As String

StartFolderName = "D:\Test" '<<<< CHANGE
Set FSO = New Scripting.FileSystemObject
For Each SubF In FSO.GetFolder(StartFolderName).SubFolders
DoSubFolder FSO, SubF, LatestDate, LatestFolderName
Next SubF

MsgBox "Latest Folder: " & CStr(LatestFolderName) & vbNewLine & _
"Latest Date: " & CStr(LatestDate)
End Sub

Sub DoSubFolder(FSO As Scripting.FileSystemObject, _
FF As Scripting.Folder, ByRef LatestDate As Long, _
ByRef LatestFolderName As String)

Dim SubF As Scripting.Folder
Dim L As Long
L = DateFromFolderName(FF)
If L LatestDate Then
LatestDate = L
LatestFolderName = FF.Path
End If
For Each SubF In FF.SubFolders
DoSubFolder FSO, SubF, LatestDate, LatestFolderName
Next SubF
End Sub

Function DateFromFolderName(FF As Scripting.Folder) As Long
Dim FolderName As String
FolderName = FF.Name
DateFromFolderName = FF.DateCreated
End Function



Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com





On Fri, 5 Mar 2010 12:00:01 -0800, SteveZmyname
wrote:

Hello
Is it possible to search through a set of folders or directories and choose
the one with the largest number? Excel has a MAX function for finding the
largest number on a ss which I need to use later but I have to find a dir
with the largest number which in turn is the newest date. It's an odd date
format.

thanks for any help
Steve

Reply
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
Finding the largest number help John Excel Discussion (Misc queries) 7 October 23rd 07 11:10 PM
Finding largest number from list holyman Excel Discussion (Misc queries) 1 July 23rd 06 11:55 PM
Finding the 3rd largest number in a list Simon Jefford Excel Worksheet Functions 2 June 28th 05 04:01 PM
finding the largest number from the last row and look up its name. Jeff Excel Worksheet Functions 5 February 24th 05 10:40 PM
finding the second largest number in a list bobf Excel Discussion (Misc queries) 1 February 16th 05 01:19 PM


All times are GMT +1. The time now is 02:26 PM.

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"