WashHandsWithChamploo
New Member
- Joined
- Aug 6, 2014
- Messages
- 11
Code:
Private Function FilterTheFileList(list() As Variant, t As String) As Variant
Dim sht As Worksheet
Dim c As Range
Dim wkBookInfo() As Variant
Dim filteredWkbInfo() As Variant
Dim filteredWksInfo() As Variant
Dim i As Long
Dim wksCnt As Long
Dim wkBookNum As Long
Dim confirmation As String
Dim fileName As String
'Dim workBookInfo As String
Application.ScreenUpdating = False
'according to my compiler error the error occurs here because apparently list isn't techincally an array...
wkBookNum = list.Length
wksCnt = 1
ReDim filteredWkbInfo(1 To wkBookNum)
For i = 1 To wkBookNum
fileName = "labInventory" & list(wkBookNum)
Workbooks.Open fileName
For Each sht In ActiveWorkbook.Worksheets
For Each c In sht.UsedRange.Rows(1).Cells
If InStr(c.Value, t) > 0 Then
filteredWksInfo(wksCnt) = ActiveWorkbook.Name + "" + sht.Name
wksCnt = wksCnt + 1
End If
Next c
Next sht
filteredWkbInfo(i) = filteredWksInfo
Next i
If IsArray(filteredWkbInfo) Then
ReDim Preserve filteredWkbInfo(1 To wkBookNum)
'workBookInfo = Join(wkBookInfo, vbNullString)
FilterTheFileList = filteredWkbInfo
Else
Application.MsgBox ("There were no matches in any of the workbooks")
End If
End Function