Like, with worksheet- UDF?

  • Thread starter Thread starter Steve
  • Start date Start date
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.
 
You cannot perform a worksheet operation on a cell from within a function,
with or without Like.
 
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.
 
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.
 
Back
Top