hk4kim,
Give this a try:
Sub tgr()
Const strFolderPath As String = "\\Fps1ids\hmkqc\Inspection_Test Sheet\QAF\"
Dim ws As Worksheet
Dim wsDest As Worksheet
Dim rngFound As Range
Dim rngKeyWords As Range
Dim KeyWordCell As Range
Dim lCalc As XlCalculation
Dim lMacroSec As MsoAutomationSecurity
Dim arrFiles() As Variant
Dim arrDieNo() As Variant
Dim arrCures() As Variant
Dim strFileName As String
Dim arrIndex As Long
Dim lMatch As Long
Set wsDest = ActiveWorkbook.Sheets("Sheet1")
Set rngKeyWords = wsDest.Range("A2", wsDest.Cells(Rows.Count, "A").End(xlUp))
If rngKeyWords.Row < 2 Then GoTo CleanExit 'No data
With Application
lCalc = .Calculation
lMacroSec = .AutomationSecurity
.Calculation = xlCalculationManual
.AutomationSecurity = msoAutomationSecurityForceDisable
.EnableEvents = False
.ScreenUpdating = False
End With
On Error GoTo CleanExit
arrIndex = 0
ReDim arrFiles(1 To 65000)
strFileName = Dir(strFolderPath & "*.xls*")
Do While Len(strFileName) > 0
arrIndex = arrIndex + 1
arrFiles(arrIndex) = strFileName
strFileName = Dir
Loop
If arrIndex > 0 Then ReDim Preserve arrFiles(1 To arrIndex) Else GoTo CleanExit
arrIndex = 0
ReDim arrDieNo(1 To rngKeyWords.Rows.Count)
ReDim arrCures(1 To rngKeyWords.Rows.Count)
On Error Resume Next
For Each KeyWordCell In rngKeyWords.Cells
arrIndex = arrIndex + 1
lMatch = 0
lMatch = WorksheetFunction.Match("*" & KeyWordCell.Text & "*", arrFiles, 0)
If lMatch > 0 Then
With Workbooks.Open(strFolderPath & arrFiles(lMatch))
For Each ws In .Sheets
If InStr(1, ws.Name, "Template", vbTextCompare) > 0 Then
Set rngFound = ws.Cells.Find("DIE #", , xlValues, xlPart)
If Not rngFound Is Nothing Then
Select Case (InStr(1, rngFound.Offset(, 4).Text, "/", vbTextCompare) > 0)
Case True: arrDieNo(arrIndex) = Trim(Replace(LCase(rngFound.Offset(, 4).Text), "hk", vbNullString))
Case Else: arrDieNo(arrIndex) = Trim(rngFound.Offset(, 4).Text)
End Select
End If
Set rngFound = ws.Cells.Find("CURE TIME", , xlValues, xlPart)
If Not rngFound Is Nothing Then arrCures(arrIndex) = CDbl(Trim(Left(Replace(WorksheetFunction.Trim(rngFound.End(xlToRight).Text), " ", String(99, " ")), 99)))
Exit For
End If
Next ws
.Close False
End With
End If
Next KeyWordCell
On Error GoTo 0
Intersect(rngKeyWords.EntireRow, wsDest.Columns("E")).Value = Application.Transpose(arrDieNo)
Intersect(rngKeyWords.EntireRow, wsDest.Columns("J")).Value = Application.Transpose(arrCures)
CleanExit:
With Application
.Calculation = lCalc
.AutomationSecurity = lMacroSec
.EnableEvents = True
.ScreenUpdating = True
End With
If Err.Number <> 0 Then Err.Clear
Set ws = Nothing
Set wsDest = Nothing
Set rngFound = Nothing
Set rngKeyWords = Nothing
Set KeyWordCell = Nothing
Erase arrFiles
Erase arrDieNo
Erase arrCures
End Sub
Bookmarks