循环以根据电子表格中的两个条件在目录中搜索丢失的文件

Loop to search for missing files in a directory based off of two criteria within a spreadsheet

我需要一个循环来根据电子表格中的两个条件在目录中搜索丢失的文件。标准在 A 列 (fundName) 和 D 列 (fundDate) 中。

基金名称的数量是动态的,有时可能是 50 或 500。 基金日期的计数是相同的,但每个季度都会发生变化。

用于用户输入的电子表格看起来像这样。

我想我需要为基金和日期组合创建一个偏移量 For 循环。

Sub Validatename()
    
    Dim fileName As Variant
    Dim answer As Integer
    Dim fundName As Variant
    Dim fundDate As Variant
    
    fundName = ThisWorkbook.Worksheets("Fund List").Range("A2")
    fundDate = ThisWorkbook.Worksheets("Fund List").Range("D2")
    
    fileName = Dir("\ykt1cnfsprd4\xOldfiles\" & "*MonthlyAccountSummary*" & "*" & fundName & "*" & fundDate & "*" & "*" & "*.xlsx*")
    
    While fileName = ""
    
        answer = MsgBox(fundName & fundDate & "monthly Account Summary is missing, would you like to continue?", vbQuestion + vbYesNo)
    
        If answer = vbNo Then Exit Sub
    
        fileName = Dir
    
    Wend

列表(列)中缺少文件

Option Explicit

Sub Validatename()
    
    Dim ws As Worksheet: Set ws = ThisWorkbook.Worksheets("Fund List")
    
    Dim nlCell As Range: Set nlCell = ws.Cells(ws.Rows.Count, "A").End(xlUp)
    Dim nrg As Range: Set nrg = ws.Range("A2", nlCell)
    
    Dim cCell As Range
    Dim FundName As String
    Dim FundDate As String
    Dim fName As String
    Dim Answer As Integer
    
    For Each cCell In nrg.Cells
        FundName = CStr(cCell.Value)
        FundDate = CStr(cCell.EntireRow.Columns("D").Value)
        fName = Dir("\ykt1cnfsprd4\xOldfiles\" & "*" & "MonthlyAccountSummary" _
            & "*" & FundName & "*" & FundDate & "*" & ".xls" & "*")
        If Len(fName) = 0 Then
            Answer = MsgBox(FundName & " " & FundDate & " " _
                & "monthly Account Summary is missing. " _
                & "Would you like to continue?", _
                vbQuestion + vbYesNo, "Missing File") 
            If Answer = vbNo Then Exit Sub
        'Else
            'Debug.Print "Found '" & fName & "'."
        End If
    Next cCell
    
End Sub