run a check on all files IN A FOLDER

oldmanwilly

Board Regular
Joined
Feb 24, 2016
Messages
221
Hi

I need help i haven't been able to work out the best way to do this:

refresh a formula in myworkbook >>> check to see if a list of file names in my worksheet match the files that are in the same folder >>>if they are, then put a yes next to the file name cell and also put the number of rows that the file has in the cell next to that one>>>if the name isn't there then just leave blank.

I have come up with the code but some bits i cant get to work, please note cell i2 contains the formula =left(cells("filename"),83), this is the only way i could think of to get the workbooks folder path.

Thanks for any help

Code:
Sub CHECKFILES()

' IN THIS FOLDER CHECK WHETHER THE FILENAME MATCHES THE ONE IN COLUMN A
Dim MYFOLDER As String
Dim myval As String
Dim myrow As Long
Dim mybook As Workbook

mybook = ThisWorkbook


MYFOLDER = Range("i2").Text

'check if the name matches the cell

For i = 2 To 67
myval = Range("a" & i).Text
if Seek.myval in myfolder = true then
myrow = 'in myfolder & myval count number of rows -1
 mybook.Activate
 
 Range("c" & i).Value = 1
 Range("d" & i).Value = myrow
 
 Else
 Range("c" & i).Value = 0
 End If
 Next i
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
adjust as needed:

Code:
' IN THIS FOLDER CHECK WHETHER THE FILENAME MATCHES THE ONE IN COLUMN A
Sub CHECKFILES()
Dim MYFOLDER As String
Dim myval As String
Dim myrow As Long
Dim mybook As Workbook
Dim vFile
Dim i As Integer


Set mybook = ThisWorkbook


MYFOLDER = Range("i2").Text


'check if the name matches the cell


For i = 2 To 67
    myval = Range("a" & i).Text
    vFile = MYFOLDER & myval
    
    If FileExists(vFile) Then
       Range("c" & i).Value = 1
       Range("d" & i).Value = myrow
     Else
        Range("c" & i).Value = 0
    End If
 Next i
End Sub


Public Function FileExists(ByVal pvFile) As Boolean
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
FileExists = FSO.FileExists(pvFile)
Set FSO = Nothing
End Function
 
Upvote 0
adjust as needed:

Code:
' IN THIS FOLDER CHECK WHETHER THE FILENAME MATCHES THE ONE IN COLUMN A
Sub CHECKFILES()
Dim MYFOLDER As String
Dim myval As String
Dim myrow As Long
Dim mybook As Workbook
Dim vFile
Dim i As Integer


Set mybook = ThisWorkbook


MYFOLDER = Range("i2").Text


'check if the name matches the cell


For i = 2 To 67
    myval = Range("a" & i).Text
    vFile = MYFOLDER & myval
    
    If FileExists(vFile) Then
       Range("c" & i).Value = 1
       Range("d" & i).Value = myrow
     Else
        Range("c" & i).Value = 0
    End If
 Next i
End Sub


Public Function FileExists(ByVal pvFile) As Boolean
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
FileExists = FSO.FileExists(pvFile)
Set FSO = Nothing
End Function

hey that works for checking if the file exists thanks! just two things though.

1. it doesn't put a value in the myrow variable do you know how to do that step?
2. is there a way for me to not stipulate the extension in the lookup, e.g. i put man.xls it looks for an xls file, put sometimes files are saved as xlsx so i want to also look for these files.

3. what is the function doing? i;ve never seen that before

thansk !
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top