View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Zone[_3_] Zone[_3_] is offline
external usenet poster
 
Posts: 373
Default Function Error, Returns 0

Would probably be better to give it a slighly different name, since SEARCH
is the name of a built-in Excel function. However, it works fine for me if
I type mary into a cell and call the function like this:

Sub Test()
MsgBox Search("mary")
End Sub

How are you calling the function?
James

wrote in message
ps.com...
This Function Is supposed to Search each sheet in the workbook, and
return 1 if it found a match and 0 if it doesnt, Can anyone help im
really stumped :|


Function Search(StrToSearch As String)
Dim sh As Worksheet
Dim SearchTxt As String
Dim rng As Range
Dim firstAddress As String
Dim IntNumber As Integer
IntNumber = 0
SearchTxt = StrToSearch

For Each sh In ThisWorkbook.Worksheets
sh.Activate
Set rng = sh.Cells.Find(What:=SearchTxt,
After:=sh.Cells.Range("A1"), _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows,
_
SearchDirection:=xlNext, MatchCase:=True)
If Not rng Is Nothing Then
Search = IntNumber + 1
Exit For
End If
Next sh

End Function