• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Check if filename contains a portion of a string

Kmahraz

Member
Hello - Looking for some to help modify the code below so that it looks for a file name that contains a string VS an exact match

Code:
Sub Run()
Dim LRow As Integer
   Dim LPath As String
   Dim LExtension As String
   Dim LContinue As Boolean
   'Initialize variables
   LContinue = True
   LRow = 2
   LPath = "C:\Users\Sophia\Downloads\New folder\"
   LExtension = ".xl*"
   'Loop through all column A values until a blank cell is found
   While LContinue
      'Found a blank cell, do not continue
      If Len(Range("A" & CStr(LRow)).Value) = 0 Then
         LContinue = False
      'Check if file exists for part number
      Else
         'Place "No" in column B if the file does NOT exist
         If Len(Dir(LPath & Range("A" & CStr(LRow)).Value & LExtension)) = 0 Then
            Range("B" & CStr(LRow)).Value = "No"
            'Place "Yes" in column B if the file does exist
         Else
            Range("B" & CStr(LRow)).Value = "Yes"
         End If
      End If
      LRow = LRow + 1
   Wend
End Sub
 
SOLVED
Replace
Code:
        If Len(Dir(LPath & Range("A" & CStr(LRow)).Value & LExtension)) = 0 Then
with
Code:
If Len(Dir(LPath & "*" &  Range("A" & CStr(LRow)).Value & "*" & LExtension)) = 0 Then
 
Back
Top