Microsoft Office Tutorials and References
In Depth Information
Text Manipulation Functions
Figure 25-4 shows this function in use. Column A contains the text used as the first argument,
and column B contains the text used as the second argument. Cell C1 contains this formula, which
was copied down the column:
=EXACTWORDINSTRING(A1,B1)
Figure 25-4: A VBA function that determines if a particular word is contained in a string.
Thanks to Rick Rothstein for suggesting this function — which is much more efficient
than my original function.
A workbook that demonstrates the EXACTWORDINSTRING function is available on the
companion CD-ROM. The filename is exact word.xlsm .
Does a cell contain text?
A number of Excel’s worksheet functions are at times unreliable when dealing with text in a cell.
For example, the ISTEXT function returns FALSE if its argument is a number that’s formatted as
Text. The following CELLHASTEXT function returns TRUE if the cell argument contains text or
contains a value formatted as Text:
Function CELLHASTEXT(cell As Range) As Boolean
‘ Returns TRUE if cell contains a string
‘ or cell is formatted as Text
Dim UpperLeft as Range
CELLHASTEXT = False
Set UpperLeft = cell.Range(“A1”)
If UpperLeft.NumberFormat = “@” Then
CELLHASTEXT = True
Exit Function
End If
If Not IsNumeric(UpperLeft.Value) Then
CELLHASTEXT = True
Exit Function
End If
End Function
 
Search JabSto ::




Custom Search