Excel's User defined functions give the user the ability to create their own custom functions. These UDFs can then be used in the same way as normal formulae such as SUM().
Below is the code for some of our favourite UDFs:
IsFormula
=Function IsFormula(Check_Cell As Range)
'=IsFormula(A1)
IsFormula = Check_Cell.HasFormula
End Function
Eval
Function eval(ref As String)
'=Eval(A1)
Application.Volatile
eval = Evaluate(ref)
End Function
FText
Function FTEXT(f As Range)
'''''''''''''''''''''''''''''''''''
'http://www.vbaexpress.com/kb/getarticle.php?kb_id=62
'=FTEXT(A1)
'''''''''''''''''''''''''''''''''''
If f.HasFormula Then
FTEXT = f.Formula
Else: FTEXT = f
End If
End Function
Countwords
Function CountWords(rRange As Range) As Long
Dim rCell As Range, lCount As Long
'''''''''''''''''''''''''''''''''''''''''
'Written by Ozgrid.com'''''''''''''''''''
'Count whole words
'=CountWords(A1) OR =CountWords(A1:A10).
'''''''''''''''''''''''''''''''''''''''''
For Each rCell In rRange
lCount = lCount + _
Len(Trim(rCell)) - Len(Replace(Trim(rCell), " ", "")) + 1
Next rCell
CountWords = lCount
End Function