Hello All, I am working with a spreadsheet with multiple worksheets. I am trying to create a search engine that will take people to a specific section in the worksheet to copy and paste the that information to a website. This is the current code I have together.
Private Sub CommandButton1_Click()
Find_Word
FindWord = "ABC"
End Sub
Sub Search()
End Sub
Dim ws As Workbook
Dim FindWord As Range, Found As Range
Dim FindWord
Dim FindWord As String
FindWord = "ABC"
End Sub
Private Sub Find_Word()
Dim FindWord As String, Found As Range
Dim notFound As Boolean
Dim yesNo As String
notFound = True
On Error Resume Next
currentSheet = ActiveSheet.Index
wordtoFind = InputBox("Please enter the word to search for")
If wordtoFind = "" Then Exit Sub
sheetCount = ActiveWorkbook.Sheets.Count
If IsError(CDbl(wordtoFind)) = False Then wordtoFind = CDbl(wordtoFind)
For counter = 1 To sheetCount
Sheets(counter).Activate
Cells.Find(What:=wordtoFind, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
If InStr(1, ActiveCell.Value, wordtoFind) Then
If HasMoreValues(counter + 1) Then 'Not completing the method and directly entering
yesNo = MsgBox("Do you want to continue search?", vbYesNo)
If yesNo = vbNo Then
notFound = False
Exit For
End If
End If
Sheets(counter).Activate
End If
Next counter
If notFound Then
MsgBox ("Word not found")
Sheets(currentSheet).Activate
End If
End Sub
Private Function HasMoreValues(ByVal sheetCounter As Integer) As Boolean
HasMoreValues = False
Dim str As String
For counter = sheetCounter To sheetCount
Sheets(counter).Activate
str = Cells.Find(What:=wordtoFind, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Value 'Not going further than this i.e. following code is not executed
If InStr(1, str, wordtoFind) Then
HasMoreValues = True
Exit For
End If
Next counter
End Function
Sub NextPart()
Dim FindWord As String, Found As Range
FindWord = "Time "
Set Found = Sheets("Macro").Columns("A:A").Find(What:=FindWord, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Found Is Nothing Then
Found.Offset(0, 1).FormulaR1C1 = "=MID(RC[-1],SEARCH(""Time"",RC[-1])+5,8)"
Else
MsgBox "No match found."
End If
End Sub
Right now it goes through each page, but the search returns no results. I am trying to search for words. Can someone help with this? - Thanks!
Bookmarks