Looking for some expert advise on Excel VBA. I have written a small piece of code that selects a column in a specific sheet and perform a find/search on the selection. When I call the function from Excel it doesn't find anything as the Range value returned by find is empty. However when I run it directly within developer window it works fine.
Please note I'm aware same could be done using existing Excel macros. But I don't want to use them for a reason. Hope you understand.
Here is the code;
Function MYFIND(x As Range) As Integer
Dim Cell As Range
Worksheets("Sheet4").Select
Columns("A:A").Select
Set Cell = Selection.Find(What:=x.Value, searchDirection:=xlNext, MatchCase:=False)
If Cell Is Nothing Then
MsgBox "search item " & x.Value & " not found in " & ActiveSheet.Name
Else
MsgBox "Found item " & Cell.Row
End If
MYFIND = 0
End Function
What could be the problem?