how to return missing values from a list.

Jake975

Board Regular
Joined
Feb 9, 2020
Messages
114
Office Version
  1. 2016
Platform
  1. Windows
This code is used to get a list of files from a given location
VBA Code:
Dim DirectoryListArray() As String
ReDim DirectoryListArray(1000)

'Loop through all the files in the directory by using Dir$ function
MyFile = Dir$("C:\Audit Reports\Disembodied\10-14-2020\*.*")
Do While MyFile <> ""
    DirectoryListArray(Counter) = MyFile
    MyFile = Dir$
    Counter = Counter + 1
Loop

'Reset the size of the array without losing its values by using Redim Preserve
ReDim Preserve DirectoryListArray(Counter - 1)
how can I have a code tell me what names are missing biased on a list in a worksheet?
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
DirectoryListArray contains the file names including file extension
The code below assumes that your "list" includes file extension

Cell to right of file name is marked "not found" if missing from folder

VBA Code:
Sub TestFiles()
    Dim myfile As String, counter As Long
    Dim f As Long, ws As Worksheet, rng As Range, Cel As Range
    Dim DirectoryListArray() As String
    ReDim DirectoryListArray(1000)

'Loop through all the files in the directory by using Dir$ function
myfile = Dir$("C:\Audit Reports\Disembodied\10-14-2020\*.*")

Do While myfile <> ""
    DirectoryListArray(counter) = myfile
    myfile = Dir$
    counter = counter + 1
Loop

'Reset the size of the array without losing its values by using Redim Preserve
    ReDim Preserve DirectoryListArray(counter - 1)

'where is the list?
    Set ws = Sheets("Sheet2")
    Set rng = ws.Range("A2", ws.Range("A" & ws.Rows.Count).End(xlUp))

'check for items in sheet list not in folder and leaving "not found" in adjacent cell
    rng.Offset(, 1).Value = "NotFound"
    For Each Cel In rng
        For f = 0 To UBound(DirectoryListArray)
            If Cel = DirectoryListArray(f) Then
                Cel.Offset(, 1).ClearContents
                Exit For
            End If
        Next f
    Next Cel
End Sub
 
Upvote 0
the lists i have doesn't have the file extensions and i would need it to display in a userform label. I'm using this to make a system check to make sure files have been saved.
here is a copy of the data table. The first column is the parts of the names that are the same and to the right is what they are saved into.
Nightaudit proccesser.xlsm
ABCDE
1Search NameExample NameCorrect NameFinal OrderHelper
2001_001_692159.pdfTitle.pdf1
3002_002_595993.pdfNew Trial Balance.pdf7
4003_003_428525.pdfManager Report.pdf6
5010_010_657038.pdfPaid Out.pdf26
6011_011_194372.pdfCashier Audit.pdf23
7013_013_677487.pdfGuest Ledger Detail.pdf21
8024_024_492359.pdfNight Auth.pdf11
9Adjustment_Adjustment Log.pdfAdjustment Log.pdf99
10artran_artransfer3762989.pdfAR Settlement.pdf18
11creditcard_creditcard_history3762975.pdfCredit Card History.pdf9
12depled_depled_321427.pdfDeposit Ledger.pdf15
13detaging_detaging_053783.pdfDetailed Aging.pdf17
14finjrnlbytransfinjrnlbytrans3762981.pdfJournal by TRA.pdf3
15finopbalallfinopbalall3762980.pdfOpen Balance.pdf13
16finpaymentsfinpayments3762982.pdfCashier Aud.pdf23
17gi_authlimitgi_authlimit3762985.pdfCredit Limit alltypes.pdf12
18gi_c_hgi_c_h3762978.pdfGuest -in COMP.pdf24
Data List

any other suggestions?
 
Upvote 0
I am totally confused ?
- pdf is the file extension.
- It is in the file names in columns B & C
BUT you say "the lists i have doesn't have the file extensions"

Please explain what you want in a way this idiot can understand
 
Upvote 0
I'm sorry DirectoryListArray(counter) will list something like "Title.pdf" or "001_692159.pdf" and these have the extensions. But in this example I can only match the file by the information before the underscore so basically any file the is saved as 001_=Title.pdf
but i would be working with pdf
 
Upvote 0
Are you looking for file names beginning with characters in column A and ending with ".pdf" ?
 
Upvote 0
Discrepancy in your data - values in column A do not match what is in column B

Adjustment_
artran_

See if this achieves what you want
- results sheet added

VBA Code:
Sub TestFiles()

    Dim myfile As String, counter As Long
    Dim f As Long, Cel As Range
    Dim fName As String, cName As String
    Dim ws As Worksheet, temp As Worksheet, rng As Range
    Dim DirectoryListArray() As String
    ReDim DirectoryListArray(1000)

'Loop through all the files in the directory by using Dir$ function
    myfile = Dir$("C:\Audit Reports\Disembodied\10-14-2020\*.*")

While myfile <> ""
    DirectoryListArray(counter) = myfile
    myfile = Dir$
    counter = counter + 1
Loop

'Reset the size of the array without losing its values by using Redim Preserve
    ReDim Preserve DirectoryListArray(counter - 1)

'where is the list
    Set ws = Sheets("Sheet2")
    Set rng = ws.Range("A2", ws.Range("A" & ws.Rows.Count).End(xlUp))

'insert sheet for results
    Set temp = Sheets.Add(before:=Sheets(1))
    temp.Range(rng.Address).Value = rng.Value
    Set rng = temp.Range(rng.Address)

'check for items in sheet list not in folder
    rng.Offset(, 1).Value = "NotFound"
    For Each Cel In rng
        For f = 0 To UBound(DirectoryListArray)
            cName = LCase(Cel)
            fName = LCase(Left(DirectoryListArray(f), Len(Cel)))
            If cName = fName Then
                Cel.Offset(, 1).ClearContents
                Exit For
            End If
        Next f
    Next Cel
End Sub
 
Upvote 0
Its not unsatisfactory Im just trying to figure out how to get the names that show up as "not found" to populate a listbox not another sheet. Other then that i think i and tweak the rest
 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,629
Members
452,661
Latest member
Nonhle

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