PC Review


Reply
Thread Tools Rate Thread

Can a custom Search function return a cell reference?

 
 
MikeM_work
Guest
Posts: n/a
 
      4th Mar 2008
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
 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      4th Mar 2008
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
--
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
 
Reply With Quote
 
MikeM
Guest
Posts: n/a
 
      4th Mar 2008
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

"Jim Cone" wrote:

> 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
> --
> 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
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I create a cell reference from ADDRESS function return? Coachdenny Microsoft Excel Worksheet Functions 3 2nd Dec 2008 04:22 AM
Search for data and return cell reference exoticdisease Microsoft Excel Worksheet Functions 3 28th Jul 2008 02:16 PM
function to find value and return cell reference rcc Microsoft Excel Misc 3 18th Jan 2008 02:50 AM
Function return by reference R Avery Microsoft Excel Programming 3 10th Aug 2004 10:43 PM
IF Function to return a reference instead of a value gin Microsoft Excel Worksheet Functions 1 22nd Sep 2003 05:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:43 PM.