Script recognizing bold text?

marko_v

New Member
Joined
Oct 18, 2006
Messages
2
I have an excel sheet with a cell which contains several sentences. I should extract three parts of text that are bolded and put them in three separate columns on another sheet. Is there any way to create a script that would recognize bold text so I could copy it then and paste it to another place. Just for the record, I have all together over 200 000 rows to check in over than 20 sheets.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
See if you can adapt this:

Code:
Sub Test()
    Dim Sh As Worksheet
    Dim Rng As Range
    Dim Cell As Range
    Dim i As Integer
    Dim ii As Integer
    Dim c As Integer
    Dim First As Integer
    Dim Last As Integer
    Set Sh = Worksheets("Sheet1")
    With Sh
        Set Rng = .Range("A1:A" & .Cells(.Rows.Count, 1).End(xlUp).Row)
    End With
    For Each Cell In Rng
        c = 2
        First = 1
        Last = 1
        For i = 1 To Len(Cell.Value)
            If Cell.Characters(i, 1).Font.Bold = True Then
                If Last < i Then
                    First = i
                    For ii = i To Len(Cell.Value)
                        If Cell.Characters(ii, 1).Font.Bold = False Then
                            Last = ii
                            Rng.Cells(Cell.Row, c).Value = Mid(Cell.Value, First, Last - First)
                            c = c + 1
                            Exit For
                        End If
                    Next ii
                End If
            End If
        Next i
    Next Cell
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,547
Members
449,089
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top