Is there way of detecting whether a cell is Bold text?

G

Guest

I have a very large spreadsheet of some data that someone else entered.

They have separated groups in the sheet by using Bold text for the first
line. I know this is a poor way of doing it but it is too late to change.
It is OK when viewing the spreadsheet but I would like to transfer it to
ACCESS because of its size.

I would like to detect the lines with bold text so that I can add a flag in
a new column to identify them. Is there any way of doing this?
 
G

Guest

hi
assuming that all the text in each line is bold you might do a loop
Sub test1()
Dim rg As Range
Dim rgd As Range
Set rg = Cells(1, 1)
Do While Not IsEmpty(rg)
Set rgd = rg.Offset(1, 0)
If rg.Font.Bold Then
rg.end(xlright).offset(0,1).value = "Flag"
End If
Set rg = rgd
Loop
End Sub

regards
FSt1
 
R

Rick Rothstein \(MVP - VB\)

If you know that the entire first line is bold, meaning you know the first
character is bold, guaranteed, then this User Defined Function will work for
you...

Function IsFirstLineBold(CellAddr As Range) As Boolean
Application.Volatile
IsFirstLineBold = CellAddr.Characters(1, 1).Font.Bold
End Function

If, on the other hand, the first line can "look" bold, but possibly have
non-bolded leading blank spaces, then this more general function (it out if
there is a bold character anywhere in the cell) would probably be what you
want...

Function IsAnythingBold(CellAddr As Range) As Boolean
Dim X As Long
Application.Volatile
For X = 1 To Len(CellAddr.Value)
If CellAddr.Characters(X, 1).Font.Bold Then
IsAnythingBold = True
Exit For
End If
Next
End Function

By the way, if you are not familiar with User Defined Function... you would
go into the VBA editor, Insert a Module and then paste one of the functions
above into its code window; then just put this...

IsFirstLineBold(A1) <<<or>>> =IsAnythingBold(A1)

into B1 (use your own cell references in place of the A1 and B1).

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top