ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Like, with worksheet- UDF? (https://www.excelbanter.com/excel-programming/441150-like-worksheet-udf.html)

Steve

Like, with worksheet- UDF?
 
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.


Bob Phillips[_4_]

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

--

HTH

Bob

"Steve" wrote in message
...
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.




Rick Rothstein

Like, with worksheet- UDF?
 
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.

--
Rick (MVP - Excel)



"Steve" wrote in message
...
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.


Rick Rothstein

Like, with worksheet- UDF?
 
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.

--
Rick (MVP - Excel)



"Rick Rothstein" wrote in message
...
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.

--
Rick (MVP - Excel)



"Steve" wrote in message
...
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.



All times are GMT +1. The time now is 08:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com