I have an Excel file with thousands of lines. Some cells are bold, others not. Usually I am able to determine which cells are bold and which are not using this UDF:

Function isBold(cellBold)
    Application.Volatile
    If cellBold.Font.Bold = True Then
        isBold = 1
    ElseIf cellBold.Font.Bold = False Then
    isBold = 0
    Else
        isBold = 0
    End If
End Function

This works well on cells that actually have bold applied to the cells EXCEPT that the data is imported and the original source alters the text from regular to bold by altering the font, not by applying bold to the cell.

For example, the regular font is 'Times New Roman' and the bold font is 'Times New Roman Bold'. Because of this, although on the page it looks as though the cell has had bold applied to it, the UDF above doesn't work.

How can I alter the UDF so that the font is identified?

有帮助吗?

解决方案

This code finds out if the font name contains "Bold" string and sets your boolean to 1 if so:

Function isBold(cellBold)
     Application.Volatile
     pos = InStr(cellBold.Font.Name, "Bold")
     If pos > 0 Then
        isBold = 1
     End If  
End Function
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top