Microsoft Office Tutorials and References
In Depth Information
The functions in this section use the following statement:
Application.Volatile True
This statement causes the function to be reevaluated when the workbook is calculated. You'll find,
however, that these functions don't always return the correct value. This is because changing cell
formatting, for example, does not trigger Excel's recalculation engine. To force a global recalculation
(and update all the custom functions), press Ctrl+Alt +F9.
The following function returns TRUE if its single-cell argument has bold formatting:
Function ISBOLD(cell As Range) As Boolean
‘ Returns TRUE if cell is bold
Application.Volatile True
ISBOLD = cell.Range(“A1”).Font.Bold
End Function
The following function returns TRUE if its single-cell argument has italic formatting:
Function ISITALIC(cell As Range) As Boolean
‘ Returns TRUE if cell is italic
Application.Volatile True
ISITALIC = cell.Range(“A1”).Font.Italic
End Function
Both of the preceding functions have a slight flaw: They return an error (#VALUE!) if the cell has mixed
formatting. For example, it's possible that only some characters in the cell are bold.
The following function returns TRUE only if all the characters in the cell are bold. If the Bold property of the
Font object returns Null (indicating mixed formatting), the If statement generates an error, and the function
name is never set to TRUE. The function name was previously set to FALSE, so that's the value returned by the
function.
Function ALLBOLD(cell As Range) As Boolean
‘ Returns TRUE if all characters in cell are bold
Dim UpperLeft As Range
Application.Volatile True
Set UpperLeft = cell.Range(“A1”)
ALLBOLD = False
If UpperLeft.Font.Bold Then ALLBOLD = True
End Function
Search JabSto ::




Custom Search