Like, with worksheet- UDF?

S

Steve

Howdee all.
Has anyone ever made a UDF, for Like, to use in a worksheet function?

I.e., look at a string of text in a cell, and see if a given format exists,
to then perform a worksheet operation on that cell's contents, based on its
matching the like operator?

I swear I remember a discussion like this before, but I can't find it.

I am aware that it's not a standard worksheet function. Hence the UDF.
 
B

Bob Phillips

You cannot perform a worksheet operation on a cell from within a function,
with or without Like.
 
R

Rick Rothstein

It should be as simple as this...

Function IsLike(TextString As String, Pattern As String) As Boolean
IsLike = TextString Like Pattern
End Function

Note that you can't call the function "Like" because that is a reserved
function name in VB, so you can't name a VB function that; hence, I chose to
call it IsLike. You can use any Like patterns for the Pattern argument.
 
R

Rick Rothstein

Of course Bob is right... you cannot perform "worksheet operations" as such,
but my IsLike function can do whatever a normal worksheet function can do.
So, you could do, say, this...

=IF(IsLike(A1,"###"),"A1 has exactly 3 digits", "Wrong number of digits")

You can also use the IsLike function in a Conditional Format in order to,
say, change the cell color if the contents of the cell meets (or doesn't
meet) a certain pattern.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Chinese New Year 4
UDF to return text 4
sumproduct in UDF 7
UDF-event mishap 1
Time within time 8
How to stop UDF in Original ref'ng copied range 6
Problem with UDF 2
is ws protected with a given password? 6

Top