Search function for a workbook
Here is some cool vba that will do what you are looking
for.
Public SearchCriteria, FirstCell As Variant
Sub findbutton_click()
'If the search criteria does not occur in the worksheet,
an error will occur.
On Error GoTo Error_Handler
'Start in cell A1
ThisWorkbook.Activate
Range("A1").Select
'Get search criteria and assign it to the variable
SearchCriteria
SearchCriteria = InputBox("Enter Store Number", "Search
Criteria")
'Perform search using SearchCriteria
Cells.Find(What:=SearchCriteria, After:=ActiveCell,
LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, MatchCase:= _
False).Select
'Assign address of first found cell to FirstCell
FirstCell = ActiveCell.Address
'Check to see if this is the desired row
FindNext:
If FindNextCell = FirstCell Then
MsgBox "You have searched the entire worksheet.",
vbOKCancel, "End of Search"
Range("A1").Activate
Exit Sub
End If
Response = MsgBox("Is this the correct cell?",
vbYesNoCancel, "Find Next")
If Response = vbNo Then
Cells.FindNext(After:=ActiveCell).Activate
FindNextCell = ActiveCell.Address
GoTo FindNext
End If
Exit Sub
Error_Handler:
MsgBox "The search criteria you entered does not occur in
the worksheet.", vbOKCancel, _
"Search Criteria Error"
End Sub
I love this one. I did this for users that had difficulty
with ctrl-f. Go figure.
Good Luck.
-----Original Message-----
Sorry, about that.
Here is more detail.
I would like it to jump to the location if the part
number
is found.
I don't know if this will work for the description as
some
description can be similiar, any suggestions for this
part, maybe just the worksheet/cell locations of matching
results.
Part numbers are mainly numeric but can be alpha-numeric.
Descriptions are text only.
Hope this helps.
-----Original Message-----
please provide more detail. what do you want returned,
if
it exist or where its located? what format is your data
in?. how is your workbook setup
----- brian wrote: -----
First, thanks for all the great help!
Here is my situation:
I have an inventory workbook that I want to add a
search
page to. I would like to actually have 2 separate
search
boxes, one to search by part number and the second
to
search by description.
Hope this is an easy one.
Thanks,
Brian
.
.
|