Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default List files in Folder if Condition is Met

Using VBA, I would like list in column A all of the .xls files included in a
generic folder whose last 5 digits before the .xls extension are greater than
5000.
Can you point me in the right direction?

Thank you.
Filo

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default List files in Folder if Condition is Met

"Can you point me in the right direction?"

If File.Name Like "*#####.xls" Then
If Val(Right$(File.Name,9)) 5000 Then
'do something
End If
End If
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Filo"
wrote in message
Using VBA, I would like list in column A all of the .xls files included in a
generic folder whose last 5 digits before the .xls extension are greater than
5000.
Can you point me in the right direction?

Thank you.
Filo

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default List files in Folder if Condition is Met

Are you sure you meant last **5** digits are greater than 5000? Or should
the 5 have been a 4? Or perhaps the 5000 should have been 50000? Assuming
you meant what you said, this macro should do what you want....

Sub FilesToColumnA()
Dim X As Long
Dim Path As String
Dim FileName As String
Path = "c:\temp\"
' This line makes sure the path ends with a back slash
If Right(Path, 1) < "\" Then Path = Path & "\"
FileName = Dir$(Path & "*.xls")
Do While Len(FileName) 0
If Val(Mid(FileName, InStr(FileName, ".") - 5, 5)) 5000 Then
Range("A1").Offset(X, 0).Value = Path & FileName
X = X + 1
End If
FileName = Dir$()
Loop
End Sub

Rick


"Filo" wrote in message
...
Using VBA, I would like list in column A all of the .xls files included in
a
generic folder whose last 5 digits before the .xls extension are greater
than
5000.
Can you point me in the right direction?

Thank you.
Filo


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default List files in Folder if Condition is Met

Awesome! I tested it and it works perfectly.
Thank you Rick

PS I learned a lot from this line:
Val(Mid(FileName, InStr(FileName, ".") - 5, 5)) 5000

"Rick Rothstein (MVP - VB)" wrote:

Are you sure you meant last **5** digits are greater than 5000? Or should
the 5 have been a 4? Or perhaps the 5000 should have been 50000? Assuming
you meant what you said, this macro should do what you want....

Sub FilesToColumnA()
Dim X As Long
Dim Path As String
Dim FileName As String
Path = "c:\temp\"
' This line makes sure the path ends with a back slash
If Right(Path, 1) < "\" Then Path = Path & "\"
FileName = Dir$(Path & "*.xls")
Do While Len(FileName) 0
If Val(Mid(FileName, InStr(FileName, ".") - 5, 5)) 5000 Then
Range("A1").Offset(X, 0).Value = Path & FileName
X = X + 1
End If
FileName = Dir$()
Loop
End Sub

Rick


"Filo" wrote in message
...
Using VBA, I would like list in column A all of the .xls files included in
a
generic folder whose last 5 digits before the .xls extension are greater
than
5000.
Can you point me in the right direction?

Thank you.
Filo



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
Getting a list of files in a Sharepoint Folder John Excel Programming 0 June 12th 07 09:58 PM
Get list of files in a folder in Excel Khoshravan Excel Programming 2 April 29th 07 01:30 PM
List files in a folder gilgil Excel Programming 2 November 23rd 05 02:02 PM
How to get the list of files in a folder yang Excel Programming 1 October 16th 03 12:53 PM
Getting list of files in a folder to excel Dave Peterson[_3_] Excel Programming 0 July 29th 03 02:47 AM


All times are GMT +1. The time now is 04:13 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"