I have a list of excel file names and those file's path in 2 columns. Using the code , I open each worksheet at a time , search for a specific keyword in opened workbook , wherever match is found. I have to get that workbook name (already have) , matched found cell address , that active sheet name and value in cell.
Query 1: Now , already have code with me it works properly but when I hide the excel sheets so that user can't see them , the ActiveSheet can't be used code does not go to opened workbook instead it search in macro file , In simple words if I hide files using .visible = false it does not work , it search values in macro. Please help to fix it
Query 2: I think the code to paste value in macro is not 100% accurate , because I have just mentioned sheets not workbook , please help to make it solid
Query 3: How to make it faster if I want to search 10k files
I have tried the below code
Dim lastvalueoffiles As Integer
lastvalueoffiles = Sheet4.Range("A" & Rows.Count).End(xlUp).Row
For EachFileinPath = 2 To lastvalueoffiles
Dim wb As Workbook
'wb.Visible = False
Set wb = Workbooks.Open(Sheet4.Cells(EachFileinPath, 2).Value)
ActiveWindow.Visible = True
Dim SearchString As String
Dim SearchRange As Range, cl As Range
Dim FirstFound As String
Dim sh As Worksheet
'''Set Search value
SearchString = Sheet1.Cells(6, 8).Value
Application.FindFormat.clear
'''loop through all sheets
For Each sh In ActiveWorkbook.Worksheets
''' Find first instance on sheet
Set cl = sh.Cells.Find(What:=SearchString, After:=sh.Cells(1, 1), LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
sh.Activate
If Not cl Is Nothing Then
' if found, remember location
FirstFound = cl.Address
' format found cell
Do
LastValueoftheresultfound = Sheet4.Cells(EachFileinPath, ActiveSheet.Columns.Count).End(xlToLeft).Column
momo = ActiveCell.Address
ActiveSheet.Select
Sheet4.Cells(EachFileinPath, LastValueoftheresultfound + 1).Value = ActiveSheet.Name
Sheet4.Cells(EachFileinPath, LastValueoftheresultfound + 2).Value = cl.Address
Sheet4.Cells(EachFileinPath, LastValueoftheresultfound + 3).Value = cl.Value
'''cl.Interior.ColorIndex = 3
Set cl = sh.Cells.FindNext(After:=cl)
' repeat until back where we started
Loop Until FirstFound = cl.Address
End If
Next
ActiveWorkbook.Close SaveChanges:=False
koko = Sheet1.Cells(6, 8).Value
Next EachFileinPath