PC Review


Reply
Thread Tools Rate Thread

Creating a UDF to search a cell's formula

 
 
kittronald
Guest
Posts: n/a
 
      24th Jul 2011
I'm trying to find a way to search for text in a cell's formula.

Is this something that could be done with a UDF ?

For example ...

SearchFormula(find_text,within_text) where find_text could be a
single value or a multi-valued named range.

If A1 contained =VLOOKUP(One,$A:$B,2,FALSE)

and C1=One, C2=Two, C3=Three

and $C$1:$C$3 was a named range called "Numbers"

The formula would look like =SEARCHFORMULA(Numbers,A1) and would
return a Boolean value of 1.

If a match wasn't found, it would return a Boolean value of 0.

Any ideas ?




- Ronald K.
 
Reply With Quote
 
 
 
 
kittronald
Guest
Posts: n/a
 
      24th Jul 2011
Made a mistake with the desired result.

The SEARCHFORMULA result should return the value found.

In the example above, if A1's formula contained the text "One", the
result should be "One".



- Ronald K.
 
Reply With Quote
 
kittronald
Guest
Posts: n/a
 
      25th Jul 2011
Ron,

That works !

Thanks for the late night save.



- Ronald K.
 
Reply With Quote
 
kittronald
Guest
Posts: n/a
 
      12th Sep 2011
Ron,

If you're still watching this thread, how could you use this
function within a macro ?



- Ronald K.
 
Reply With Quote
 
kittronald
Guest
Posts: n/a
 
      13th Sep 2011
Ron,

Thanks for the quick response.

Could this function be adapted to search a formula in a defined name's
Refers to: field ?



- Ronald K.


 
Reply With Quote
 
kittronald
Guest
Posts: n/a
 
      14th Sep 2011
Ron,

I've been trying to get
=SEARCHFORMULA(Numbers,ActiveSheet.Names("Numbers_Formula").RefersTo) to
work.

However, given my limited development skills, it appears this is beyond
my ability.

Perhaps, there's another way.

Thanks for getting back to me.



- Ronald K.


 
Reply With Quote
 
kittronald
Guest
Posts: n/a
 
      24th Sep 2011
Ron,

I've tried the following, but the debugger keeps displaying a Run-
time error '13': Type mismatch.


Option Explicit
Function SEARCHFORMULA(find_text As Variant, within_text As Variant)
As Variant
Dim vFindText As Variant
Dim s As Variant
Dim i As Long
s = within_text
vFindText = find_text
SEARCHFORMULA = 0


For i = LBound(vFindText) To UBound(vFindText)
If InStr(1, s, vFindText(i, 1), vbTextCompare) > 1 Then
SEARCHFORMULA = vFindText(i, 1)
Exit For
End If
Next i
End Function


What is it that I'm not setting correctly ?



- Ronald K.
 
Reply With Quote
 
kittronald
Guest
Posts: n/a
 
      27th Sep 2011
Ron,

When stepping through the code, the following line causes the error:

For i = LBound(vFindText) To UBound(vFindText)

When using SEARCHFORMULA as a UDF in a cell, Find_text is a named range
(i.e., Sheet1!$A$1:$A$5) and Within_text is the Refers to: field of a name.

The difference between using the SEARCHFORMULA UDF in a cell and in a
macro is the data type of Within_text.

The cell version uses a defined name for Within_text that contains a
text string (i.e. =CONCATENATE("SUM","PRODUCT")).

The macro version uses a name's Refers to: field.

How can I tell what data type is being expected ?




- Ronald K.


 
Reply With Quote
 
kittronald
Guest
Posts: n/a
 
      27th Sep 2011
Ron,

When stepping through the code, the following line causes the error:

For i = LBound(vFindText) To UBound(vFindText)

When using SEARCHFORMULA as a UDF in a cell, Find_text is a named range
(i.e., Sheet1!$A$1:$A$5) and Within_text is the Refers to: field of a name.

The difference between using the SEARCHFORMULA UDF in a cell and in a
macro is the data type of Within_text.

The cell version uses a defined name for Within_text that contains a
text string (i.e. =CONCATENATE("SUM","PRODUCT")).

The macro version uses a name's Refers to: field.

How can I tell what data type is being expected ?




- Ronald K.


 
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
creating a formula that looks at the value of another cell and usesthat value as the row value for for a referenced cell Kerry Microsoft Excel Charting 2 16th Mar 2010 12:29 AM
creating a blank formula cell Stephen Microsoft Excel Discussion 3 9th Sep 2008 03:04 PM
Creating a Search Cell =?Utf-8?B?Q29uZnVzZWQgYXQgV29yaw==?= Microsoft Excel Misc 3 25th Sep 2007 01:51 PM
need help creating formula based on cell value =?Utf-8?B?QnJhZA==?= Microsoft Excel Misc 3 1st Apr 2005 07:51 PM
Creating a formula that references the formula in another cell robin.chappell Microsoft Excel Misc 1 21st Aug 2004 09:17 PM


Features
 

Advertising
 

Newsgroups
 


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