+ Reply to Thread
Results 1 to 3 of 3

Check if a filename contains (not equals) the value of a cell

Hybrid View

  1. #1
    Registered User
    Join Date
    06-14-2013
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    5

    Check if a filename contains (not equals) the value of a cell

    Hi! Sorry if my formatting is incorrect, I haven't posted here before.

    Edit: I am very new to VBA, by the way!

    I have a column of part numbers and I'm working on filling out columns of info about that part. Some of this info comes from SolidWorks drawings which are contained in a .dwg file.

    This is the code I found to check if the file exists that equals the cell value.

    Sub CheckIfFileExists()
    
       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\myname\Desktop\"
       LExtension = ".txt"
        
       '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
    If I have "Hello" in a cell, and "Hello.txt" on my desktop, it returns Yes which is great; however, the .dwg files would probably show up like "3123Hello3295889.dwg," which, obviously, returns no. Is there any way to check if a filename CONTAINS the cell value instead?
    Last edited by kevv; 06-14-2013 at 12:50 PM. Reason: Additional info

  2. #2
    Registered User
    Join Date
    06-14-2013
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Check if a filename contains (not equals) the value of a cell

    Just bumping because I would love this solution sooner rather than later D:

  3. #3
    Registered User
    Join Date
    06-14-2013
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Check if a filename contains (not equals) the value of a cell

    Bump - No response!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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