+ Reply to Thread
Results 1 to 9 of 9

Search files in folder based on search string

Hybrid View

djvice Search files in folder based... 09-21-2008, 01:57 PM
Leith Ross Hello djvice, Did you want... 09-21-2008, 02:11 PM
djvice Single directory. After... 09-21-2008, 02:18 PM
Leith Ross Hello djvice, This macro... 09-21-2008, 03:40 PM
djvice Hmmm....im trying to run the... 09-21-2008, 05:22 PM
Leith Ross Hello djvice, Sorry about... 09-21-2008, 06:22 PM
djvice You're a freakin' genius! ;) 09-21-2008, 07:19 PM
djvice How do I add a Msgbox if no... 09-22-2008, 12:16 AM
Leith Ross Hello djvice, At the end... 09-22-2008, 01:12 AM
  1. #1
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello djvice,

    Did you want to search a specific directory or multiple directories?

    Sincerely,
    Leith Ross

  2. #2
    Registered User
    Join Date
    12-25-2004
    Posts
    61
    Single directory.

    After pondering it some more, I think it would be best to list the filenames in Sheet1 under column A. That way, if there are more than 1 results, it can list all files with the search criteria.

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello djvice,

    This macro will start listing files in the specified directory that match the account number input by the user. The list starts on Sheet1 A1. You can change these if you need to. They are marked in red.
    Sub ListFileNames()
    
      Dim FileName As String
      Dim FilePath As String
      Dim Valid As Boolean
      Dim Wks As Worksheet
      
        R = 1    'Starting Row
        Set Wks = Worksheets("Sheet1")
        FilePath = "C:\Documents and Settings\Owner\My Documents\*.xls"
        
    InputAcct:
         Acct = InputBox("Please Enter an Account number.")
           If Acct = "" Then Exit Sub
             Valid = Acct Like "#####"
             If Not Valid Then
               MsgBox "Please Enter a 5 digit Account number."
               GoTo InputAcct
             End If
           
         FileName = Dir(FilePath)
         
         Do While FileName <> ""
           FileName = Dir()
           Valid = FileName Like "####-##### ("
             If Valid Then
               If Mid(FileName, 6, 5) = Acct Then
                 Wks.Cells(R, "A") = FileName
                 R = R + 1
               End If
             End If
         Loop
         
    End Sub
    Sincerely,
    Leith Ross
    Last edited by Leith Ross; 09-21-2008 at 03:46 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Default folder for saving files
    By Karamazov in forum Excel General
    Replies: 3
    Last Post: 06-09-2008, 03:22 PM
  2. Excel files replicating and renaming in a folder
    By hpum in forum Excel General
    Replies: 0
    Last Post: 07-21-2007, 09:23 AM
  3. Apply the same macro code to all excel files in a folder
    By Alano in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-09-2007, 09:26 AM
  4. How do to search for a string in excel across all rows/columns and save the result?
    By akondeti in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-07-2006, 07:16 PM
  5. ¿How could i search a string from Book 1 into Book2?
    By Actarus in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-27-2006, 02:21 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1