Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default [Help Needed] Custom Lookup Function


Hello

I'm writing a custom lookup function to deal with certain requirement.
This is my use case.

I've an Excel Workbook with multiple sheets. First Sheet is the "Master
Data". In one of the other sheets I've a value which I want to look up
in "Master Data" sheet and get the row number. Simple.

I've written this function


Code:
--------------------

Function foo(lookup As Range)
Dim foundCell As Range

With Sheets("Master Data").UsedRange
Set foundCell = .Find(lookup.Value)
If Not foundCell Is Nothing Then
foo = foundCell.Address
Else
foo = " :( "
End If
End With

End Function

--------------------


But for some reason my function always returns :(, meaning it didn't
find the value in the "Master Data" sheet. I'm pretty sure it is
there.

Same Function when converted to SUB and with hard coded lookup value
returns correctly.

Please help me out... what am I missing???


--

------------------------------------------------------------------------
's Profile: http://www.excelforum.com/member.php...o&userid=26151
View this thread: http://www.excelforum.com/showthread...hreadid=394788

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default [Help Needed] Custom Lookup Function

When you do a find (either manually or via code), excel remembers the last
settings (part vs whole, matchcase, all that stuff).

You might have better luck if you specify all the settings you want in your
..find statement.

" wrote:

Hello

I'm writing a custom lookup function to deal with certain requirement.
This is my use case.

I've an Excel Workbook with multiple sheets. First Sheet is the "Master
Data". In one of the other sheets I've a value which I want to look up
in "Master Data" sheet and get the row number. Simple.

I've written this function

Code:
--------------------

Function foo(lookup As Range)
Dim foundCell As Range

With Sheets("Master Data").UsedRange
Set foundCell = .Find(lookup.Value)
If Not foundCell Is Nothing Then
foo = foundCell.Address
Else
foo = " :( "
End If
End With

End Function

--------------------

But for some reason my function always returns :(, meaning it didn't
find the value in the "Master Data" sheet. I'm pretty sure it is
there.

Same Function when converted to SUB and with hard coded lookup value
returns correctly.

Please help me out... what am I missing???

--

------------------------------------------------------------------------
's Profile: http://www.excelforum.com/member.php...o&userid=26151
View this thread: http://www.excelforum.com/showthread...hreadid=394788


--

Dave Peterson
Reply
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
Lookup or reference function needed Fire Guy Excel Worksheet Functions 3 November 24th 06 11:23 PM
custom macro needed Stuart Excel Discussion (Misc queries) 16 December 6th 05 09:26 PM
VBA Custom function for lookup Sami82 Excel Worksheet Functions 9 September 12th 05 03:20 PM
Custom percent format needed Will Fleenor Excel Worksheet Functions 1 June 29th 05 02:57 AM
Desperate -Lookup function needed! Krefty[_3_] Excel Programming 4 December 31st 03 04:52 PM


All times are GMT +1. The time now is 11:48 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"