Hi there, i have this code that could extract out Data from many closed workbook. I am extracting data from 2-3 thousand files and the Data in those files are rather dynamically positioned.
For e.g. My vba codings will extract data from cell B256 of the closed workbook. Sometimes, the data might not start from that cell which my vba would still extract that non-relevant data.
Is there anyway i can modify the codings to search for the required data and extract instead of extracting it dumbly?
Code
Sub getINFO()
Dim lCount As Long
Dim wbResults As Workbook
Dim wbCodeBook As Workbook
Dim rCell As Range
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
On Error Resume Next
Set wbCodeBook = ThisWorkbook
With Application.FileSearch
.NewSearch
'Change path to suit
.LookIn = Range("H4").Value
.Filename = Range("H5").Value
If .Execute > 0 Then 'Workbooks in folder
For lCount = 1 To .FoundFiles.Count 'Loop through all.
'Open Workbook x and Set a Workbook variable to it
Set wbResults = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)
Set rCell = wbCodeBook.Sheets(1).Range("A50000").End(xlUp).Offset(1, 0)
rCell.FormulaR1C1 = wbResults.Sheets(1).Range("C256")
rCell.Offset(0, 1).FormulaR1C1 = wbResults.Sheets(1).Range("B256")
rCell.Offset(1, 0).FormulaR1C1 = wbResults.Sheets(1).Range("C257")
rCell.Offset(1, 1).FormulaR1C1 = wbResults.Sheets(1).Range("B257")
rCell.Offset(2, 0).FormulaR1C1 = wbResults.Sheets(1).Range("C258")
rCell.Offset(2, 1).FormulaR1C1 = wbResults.Sheets(1).Range("B258")
wbResults.Close SaveChanges:=True
Next lCount
End If
End With
ActiveWorkbook.Save
On Error GoTo 0
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
Display More