+ Reply to Thread
Results 1 to 4 of 4

Check if files exist from list in Column A in folder/subfolders and return "True"

  1. #1
    Registered User
    Join Date
    05-20-2020
    Location
    USA
    MS-Off Ver
    10
    Posts
    28

    Check if files exist from list in Column A in folder/subfolders and return "True"

    Hello,

    I am attempting to have an Excel VBScript to return the file path and also "True" if files exist in a folder and or subfolders based on file names in column A.

    Here is an example of the file structure:

    J0wbl.png


    I've started the code but I've gotten a little lost. Any help will be greatly appreciated!

    Here is the code I have so far:

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    09-03-2015
    Location
    IE
    MS-Off Ver
    2003 - 2016
    Posts
    258

    Re: Check if files exist from list in Column A in folder/subfolders and return "True"

    Where have you 'got lost'?. It works fine, after you add a couple of lines to update the worksheet and perhaps increment the counter used for the message box at the end...

  3. #3
    Registered User
    Join Date
    05-20-2020
    Location
    USA
    MS-Off Ver
    10
    Posts
    28

    Re: Check if files exist from list in Column A in folder/subfolders and return "True"

    Hello,

    How do you compare if the file name is found?

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hello, try this !


    A VBA basics demonstration for starters to paste to the top of a module (better the worksheet module) :

    PHP Code: 
    Dim M$(), N&

    Function 
    DirList(SCAN$, Optional FOLD$, Optional ATTR As VbFileAttribute vbNormal) As String()
             
    Dim B%, D$, F$, T$(), U&
        
    With Application
            
    If FOLD "" Then
                
    If Right(FOLD1) <> .PathSeparator And Left(SCAN1) <> .PathSeparator Then FOLD FOLD & .PathSeparator
                D 
    FOLD
            
    Else
                
    Left$(SCANInStrRev(SCAN, .PathSeparator))
            
    End If
        
    End With
            
    If SCAN "." Then SCAN "*."
            
    On Error Resume Next
            F 
    Dir$(FOLD SCANATTR)
        Do 
    Until F ""
            
    If ATTR And vbDirectory Then B Right(F1) = "." Or (GetAttr(F) And vbDirectory) = 0
            
    If 0 Then U 1ReDim Preserve T(1 To U): T(U) = FOLD F
            F 
    Dir$
        
    Loop
             DirList 
    IIf(UTSplit(""))
    End Function

    Sub DirScan(WHAT$, ByVal FROM$)
        
    Dim S$(), L&, V
            S 
    DirList(WHATFROM)
            If 
    UBound(S) > 0 Then ReDim Preserve M(1 To N UBound(S)): For 1 To UBound(S): 1M(N) = S(L): Next
            
    For Each V In DirList("*"FROMvbDirectory):  DirScan WHATV:  Next
    End Sub

    Sub Demo1
    ()
             
    Dim AVW
             ReDim M
    (1 To 1)
             
    0
        With Range
    ("A2", [A1].End(xlDown)).Columns
            
    .Item("B:C").ClearContents
        With Application
    .FileDialog(4)
            If .
    Show Then DirScan "*", .SelectedItems(1) Else Exit Sub
        End With
             A 
    = .Item(1).Value2
             V 
    = .Item("B:C").Value2
        With Application
            
    For 1 To UBound(A)
                
    = .Match("*" & .PathSeparator A(N1), M0)
                
    V(N1) = IsNumeric(W)
                If 
    V(N1Then V(N2) = Left(M(W), InStrRev(M(W), .PathSeparator))
            
    Next
        End With
            
    .Item("B:C") = V
            
    .Item(3).AutoFit
        End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 04-29-2022 at 12:43 PM. Reason: optimization, simplification …

+ 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. [SOLVED] "SOLVED" Creating a drop down list from a files in a folder
    By fishbone74 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 11-14-2021, 11:09 PM
  2. [SOLVED] Column X-Ref list - Sheet1 Col A "pages", Col B:FL "Req" to Sheet2 ColA "req", ColB "page"
    By excel-card-pulled in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 04-07-2017, 09:30 AM
  3. [SOLVED] Macro To Look at list of files in column "A" and show their last Saved Date in Column "B"
    By drknot in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-29-2015, 09:48 AM
  4. [SOLVED] Check next row if value is, "FALSE," if "TRUE," return specified value from this row
    By Dave_Doodle in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 01-19-2015, 10:18 AM
  5. Formula to return the number of continuous "true" values at the end of a list
    By mustangsally in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 04-10-2014, 11:00 AM
  6. Replies: 5
    Last Post: 01-23-2014, 11:02 AM
  7. If "text" exist within "cell" then TRUE
    By JemyM in forum Excel - New Users/Basics
    Replies: 7
    Last Post: 09-16-2005, 07:41 PM

Tags for this Thread

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