2nd part of the code :
'Macro to find values (FilterValue 1 & 2) in the Job Checklists contained in the folder.
Sub Get_Filter(FileNameInA As Boolean, SourceShName As String, _
SourceShIndex As Integer, FilterRng As String, FilterField As Integer, _
FilterValue1 As String, FilterValue2 As String, myReturnedFiles As Variant)
Dim SourceRange As Range, destrange As Range
Dim mybook As Workbook, BaseWks As Worksheet
Dim rnum As Long, CalcMode As Long
Dim SourceSh As Variant
Dim rng As Range
Dim RwCount As Long
Dim I As Long
Dim z As Long
Dim vHdr As Variant
Dim Counter As Integer
'Change ScreenUpdating, Calculation and EnableEvents
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
.EnableEvents = False
End With
'Add a new workbook with one sheet named "FO To Do List"
Set BaseWks = Workbooks.Add(xlWBATWorksheet).Worksheets(1)
BaseWks.Name = "FO To Do List"
'Set start row for the Data
rnum = 2
'Check if we use a named sheet or the Sheet index
If SourceShName = "" Then
SourceSh = SourceShIndex
Else
SourceSh = SourceShName
End If
'Loop through all files in the array of found files(myFiles)
For I = LBound(myReturnedFiles) To UBound(myReturnedFiles)
Set mybook = Nothing
On Error Resume Next
Set mybook = Workbooks.Open(myReturnedFiles(I))
On Error GoTo 0
If Not mybook Is Nothing Then
'Set SourceRange and check if it is a valid range
On Error Resume Next
With mybook.Sheets(SourceSh)
Set SourceRange = Application.Intersect(.UsedRange, .Range(FilterRng))
End With
If Err.Number > 0 Then
Err.Clear
Set SourceRange = Nothing
Else
'If SourceRange use all columns then skip this file
If SourceRange.Columns.Count >= BaseWks.Columns.Count Then
Set SourceRange = Nothing
End If
End If
On Error GoTo 0
If Not SourceRange Is Nothing Then
'Find the last row in BaseWks
rnum = RDB_Last(1, BaseWks.Cells) + 1
With SourceRange.Parent
Set rng = Nothing
'Firstly, remove the AutoFilter
.AutoFilterMode = False
'Filter the range on the FilterField column (Weeks to Go)
SourceRange.AutoFilter Field:=FilterField, _
Criteria1:=FilterValue1, _
Criteria2:=FilterValue2
With .AutoFilter.Range
'Check if there are results after you use AutoFilter
RwCount = .Columns(1).Cells. _
SpecialCells(xlCellTypeVisible).Cells.Count - 1
If RwCount = 0 Then
'There is no data, only the header
Else
'Set a range without the Header row
Set rng = .Resize(.Rows.Count + 1, .Columns.Count). _
Offset(1, 0).SpecialCells(xlCellTypeVisible)
If FileNameInA = True Then
'Copy the range and the file name
If rnum + RwCount < BaseWks.Rows.Count Then
BaseWks.Cells(rnum, "A").Resize(RwCount).Value _
= mybook.Name
rng.Copy BaseWks.Cells(rnum, "B")
End If
Else
'Copy the range
If rnum + RwCount < BaseWks.Rows.Count Then
rng.Copy BaseWks.Cells(rnum, "A")
End If
End If
End If
End With
'Remove the AutoFilter
.AutoFilterMode = False
End With
End If
'Close the "JOB CHECKLIST *" without saving
mybook.Close savechanges:=False
End If
'Open the next workbook
Next I
Bookmarks