Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Can a custom Search function return a cell reference?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MikeM_work - 04 Mar 2008 03:05 GMT
I am trying to create a custom function that will return a cell reference for
a search result.  So far, I have this:

Function FindS(MySrch) As String

AC = Cells.Find(What:=MySrch, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
       :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
       False, SearchFormat:=False).Address
       
       Ans = MsgBox("Search result (" & AC & ")", vbOKOnly, "RESULT")
   
End Function

I can capture the cell address in a message box but the active cell (where
the formula is) is empty.  Ulitimately, I want to plug the results of 'FindS'
into another formula.

Everything  I've tried has resulted in an error.
I feel like I'm close but I'm doing something fundamentally wrong.

Any ideas?

Thanks.

Mike
Jim Cone - 04 Mar 2008 03:41 GMT
You have to assign the result to the function...
'--
Function FindS(ByRef MySrch As Variant) As String
Dim AC As String
AC = Cells.Find(What:=MySrch, After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Address
FindS = AC
End Function
Signature

Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)

"MikeM_work"
wrote in message
I am trying to create a custom function that will return a cell reference for
a search result.  So far, I have this:

Function FindS(MySrch) As String

AC = Cells.Find(What:=MySrch, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
       :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
       False, SearchFormat:=False).Address
       
       Ans = MsgBox("Search result (" & AC & ")", vbOKOnly, "RESULT")
   
End Function

I can capture the cell address in a message box but the active cell (where
the formula is) is empty.  Ulitimately, I want to plug the results of 'FindS'
into another formula.

Everything  I've tried has resulted in an error.
I feel like I'm close but I'm doing something fundamentally wrong.

Any ideas?

Thanks.

Mike

MikeM - 04 Mar 2008 13:20 GMT
Dear Jim:
Thanks so much for your quick reply.  
As you might have guessed, I'm just getting started with VBA...  
A simple but important step!
Mike

> You have to assign the result to the function...
> '--
[quoted text clipped - 5 lines]
> FindS = AC
> End Function
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.