BrendanDixon
Board Regular
- Joined
- Mar 7, 2010
- Messages
- 174
- Office Version
- 365
- 2019
- Platform
- Windows
Hi All,
I am trying to add a search function to my excel document that I am using as a phone book. I have an index sheet where I would like to have the search button and then multiple sheets with the contacts in ie. "A", "B", "C" I would like to press the button and a search box pops up where I insert the text. then click search and it will go to the value. I would also like to be able to search for multiple instances with a next button or so.
This is all I have been able to find. PS I would like something that is not case sensitive.
I am trying to add a search function to my excel document that I am using as a phone book. I have an index sheet where I would like to have the search button and then multiple sheets with the contacts in ie. "A", "B", "C" I would like to press the button and a search box pops up where I insert the text. then click search and it will go to the value. I would also like to be able to search for multiple instances with a next button or so.
This is all I have been able to find. PS I would like something that is not case sensitive.
Code:
Sub Find_Data()
Dim datatoFind
Dim sheetCount As Integer
Dim counter As Integer
Dim currentSheet As Integer
On Error Resume Next
currentSheet = ActiveSheet.Index
datatoFind = InputBox("Please enter the value to search for")
If datatoFind = "" Then Exit Sub
sheetCount = ActiveWorkbook.Sheets.Count
If IsError(CDbl(datatoFind)) = False Then datatoFind = CDbl(datatoFind)
For counter = 1 To sheetCount
Sheets(counter).Activate
Cells.Find(What:=datatoFind, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
If ActiveCell.Value = datatoFind Then Exit Sub
Next counter
If ActiveCell.Value <> datatoFind Then
MsgBox ("Value not found")
Sheets(currentSheet).Activate
End If
End Sub