LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default FIND method doesn't work in UDF. What's wrong with this code?

Windows XP - Excel 2000
Hello,
I'm trying to make a function that returns the row number of the cell
in range SAR where string CRIT appears for the first time.
The purpose is to use the result as an argument in an INDEX function to
retrieve the value of the intersection of a certain row and column.

The INDEX(MATCH,MATCH) formula is useless in this case since the
horizontal criteria are not on the same row.

What is wrong with the following code ? I always get the #VALUE!
result. (I know about line breaking underscores missing in this
message. They are OK in the module.)

Function GetRowNumber(SAR As Range, CRIT As String) As Long
GetRowNumber = SAR.Find(What:=CRIT, After:=SAR.Range("A1"),
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False).Row
End Function

THE FOLLOWING SUB-VERSION WORKS FINE THOUGH.
Sub RowNum()
Dim SAR As Range, CRIT As String
Set SAR = Application.InputBox("Select Search Area", Type:=8)
CRIT = Application.InputBox("Enter Search Value", Type:=2)
MsgBox SAR.Find(What:=CRIT, After:=SAR.Range("A1"), LookIn:=xlFormulas,
_
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False).Row
End Sub

Can anyone help me out here?
Thank you very much
Herman

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
BreakLinks method doesn't work. Gop Excel Discussion (Misc queries) 0 September 1st 05 12:27 PM
How Come Calcs are wrong when verifing totals to items method beejee Excel Worksheet Functions 2 May 11th 05 05:49 AM
Using variables to make a date and using find method to find that. KyWilde Excel Programming 2 April 21st 05 09:43 PM
Find Method doesn't work Slugo Excel Programming 2 November 18th 03 03:09 PM
Cant get my code work. Find file or create it Poseilus Excel Programming 1 October 12th 03 03:42 PM


All times are GMT +1. The time now is 12:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"