gibbo1715
09-14-2005, 01:53 AM
All
Im using the function below to search a sheet
Function fnFind(strFind, Optional sh) As Range
If IsMissing(sh) Then Set sh = ActiveSheet
On Error Resume Next
Set fnFind = sh.Cells.Find(What:=strFind, _
After:=ActiveCell, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
End Function
Sub TestfnFind()
Dim SearchFor As Range
Set SearchFor = fnFind(InputBox("What do you want to search for", "Search"), Sheet1)
If SearchFor Is Nothing Then
MsgBox ("Sorry Not Found")
Else
Sheets("Sheet1").Select ' Better way of coding this line?
SearchFor.Select
End If
End Sub
To get my results i am using the line Sheets("Sheet1").Select and was wondering if there was a better way of doing this?
Cheers
Gibbo
Im using the function below to search a sheet
Function fnFind(strFind, Optional sh) As Range
If IsMissing(sh) Then Set sh = ActiveSheet
On Error Resume Next
Set fnFind = sh.Cells.Find(What:=strFind, _
After:=ActiveCell, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
End Function
Sub TestfnFind()
Dim SearchFor As Range
Set SearchFor = fnFind(InputBox("What do you want to search for", "Search"), Sheet1)
If SearchFor Is Nothing Then
MsgBox ("Sorry Not Found")
Else
Sheets("Sheet1").Select ' Better way of coding this line?
SearchFor.Select
End If
End Sub
To get my results i am using the line Sheets("Sheet1").Select and was wondering if there was a better way of doing this?
Cheers
Gibbo