searchlight
Board Regular
- Joined
- Dec 25, 2009
- Messages
- 112
(Second attempt to send this through)
I have a workbook named Search.xls
The code below searches through any open workbooks for a string entered through an input form.
The results are returned in a message box for each click that is executed and each positive result. (a lot of clicking)
I would like to have the results of the search returned to the Search.xls workbook with the cell reference in column A and the workbook name it was found in, in column B.
I appreciate any help.
Sub SearchBooks()
SearchWord = InputBox("Enter the string to search for")
For i = 1 To Workbooks.Count
Workbooks(i).Activate
For j = 1 to Sheets.Count
Worksheets(j).Activate
Range("A1").Activate
FindAnother:
Set WordAddress = Cells.Find(What:=SearchWord, after:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
If WordAddress Is Nothing Then
MsgBox ActiveWorkbook.Name & Chr(13) & "Search string not found"
Else:
If WordAddress.Address = CheckCell Then GoTo NextBook
If ActiveCell.Address = "$A$1" Then CheckCell = WordAddress.Address
Address = WordAddress.Address
MsgBox ActiveWorkbook.Name & Chr(13) & ActiveSheet.Name & Chr(13) & Address
Range(Address).Activate
GoTo FindAnother
End If
Next j
NextBook:
Next i
End Sub
I have a workbook named Search.xls
The code below searches through any open workbooks for a string entered through an input form.
The results are returned in a message box for each click that is executed and each positive result. (a lot of clicking)
I would like to have the results of the search returned to the Search.xls workbook with the cell reference in column A and the workbook name it was found in, in column B.
I appreciate any help.
Sub SearchBooks()
SearchWord = InputBox("Enter the string to search for")
For i = 1 To Workbooks.Count
Workbooks(i).Activate
For j = 1 to Sheets.Count
Worksheets(j).Activate
Range("A1").Activate
FindAnother:
Set WordAddress = Cells.Find(What:=SearchWord, after:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
If WordAddress Is Nothing Then
MsgBox ActiveWorkbook.Name & Chr(13) & "Search string not found"
Else:
If WordAddress.Address = CheckCell Then GoTo NextBook
If ActiveCell.Address = "$A$1" Then CheckCell = WordAddress.Address
Address = WordAddress.Address
MsgBox ActiveWorkbook.Name & Chr(13) & ActiveSheet.Name & Chr(13) & Address
Range(Address).Activate
GoTo FindAnother
End If
Next j
NextBook:
Next i
End Sub