copy only bold text

Karnitg

New Member
Joined
Oct 14, 2020
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
Hey.
It's a bit compicated, so you can answer just part 1...
I have a lot of text in my excel, and some of the text in the cell might be bold.
part 1:
I would like to copy only the bold text from (E1:E500) to (F1:F500) in the cell next to the original.
each bold can be 1 word or a few
part 2:
in a cell there might be a few bold "groups"
I would want the first group to be in the cell next to the original, and each of the next groups on the next cells.
if a cell is already full, go the next one available.
 

Attachments

  • 1111.png
    1111.png
    23.4 KB · Views: 14

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hello,

Have created a cumbersome macro for part 1, sure there is a more efficient method

VBA Code:
Sub COPY_BOLD()
    Application.ScreenUpdating = False
    For MY_ROWS = 1 To Range("E" & Rows.Count).End(xlUp).Row
        For MY_COUNT = 1 To Len(Range("E" & MY_ROWS).Value)
            With Range("E" & MY_ROWS).Characters(Start:=MY_COUNT, Length:=1).Font
                    If .FontStyle = "Bold" Then
                        MY_WORD = MY_WORD & Mid(Range("E" & MY_ROWS), MY_COUNT, Length:=1)
                        MY_FOUND = "Y"
                        If MY_COUNT = Len(Range("E" & MY_ROWS).Value) Then
                            Range("F" & MY_ROWS).Value = MY_WORD
                            MY_WORD = ""
                            MY_FOUND = ""
                        End If
                    Else
                        If .FontStyle <> "Bold" And MY_FOUND = "Y" Then
                            Range("F" & MY_ROWS).Value = MY_WORD
                            MY_FOUND = ""
                            MY_WORD = ""
                            GoTo FOUND_1
                        End If
                    End If
                End With
        Next MY_COUNT
FOUND_1:
    Next MY_ROWS
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hello,

Have created a cumbersome macro for part 1, sure there is a more efficient method

VBA Code:
Sub COPY_BOLD()
    Application.ScreenUpdating = False
    For MY_ROWS = 1 To Range("E" & Rows.Count).End(xlUp).Row
        For MY_COUNT = 1 To Len(Range("E" & MY_ROWS).Value)
            With Range("E" & MY_ROWS).Characters(Start:=MY_COUNT, Length:=1).Font
                    If .FontStyle = "Bold" Then
                        MY_WORD = MY_WORD & Mid(Range("E" & MY_ROWS), MY_COUNT, Length:=1)
                        MY_FOUND = "Y"
                        If MY_COUNT = Len(Range("E" & MY_ROWS).Value) Then
                            Range("F" & MY_ROWS).Value = MY_WORD
                            MY_WORD = ""
                            MY_FOUND = ""
                        End If
                    Else
                        If .FontStyle <> "Bold" And MY_FOUND = "Y" Then
                            Range("F" & MY_ROWS).Value = MY_WORD
                            MY_FOUND = ""
                            MY_WORD = ""
                            GoTo FOUND_1
                        End If
                    End If
                End With
        Next MY_COUNT
FOUND_1:
    Next MY_ROWS
    Application.ScreenUpdating = True
End Sub
hey. first of all thank you so much for the effort. unfortunately it didn't work. not sure why.
 
Upvote 0
It does work to pick the first bold word but it doesn't do anything and doesn't keep looking but go to the next row.

Try this modification. It'll show the bold word in a message box.

VBA Code:
Sub COPY_BOLD()
Dim MY_ROWS As Integer
Dim MY_COUNT As Integer
Dim MY_WORD As String
Dim MY_FOUND As String


    Application.ScreenUpdating = False
    For MY_ROWS = 1 To Range("E" & Rows.Count).End(xlUp).Row
        For MY_COUNT = 1 To Len(Range("E" & MY_ROWS).Value)
            With Range("E" & MY_ROWS).Characters(Start:=MY_COUNT, Length:=1).Font
                    If .FontStyle = "Bold" Then
                        MY_WORD = MY_WORD & Mid(Range("E" & MY_ROWS), MY_COUNT, Length:=1)
                        MY_FOUND = "Y"
                        If MY_COUNT = Len(Range("E" & MY_ROWS).Value) Then
                            Range("F" & MY_ROWS).Value = MY_WORD
                            MY_WORD = ""
                            MY_FOUND = ""
                        End If
                    Else
                        If .FontStyle <> "Bold" And MY_FOUND = "Y" Then
                        MsgBox MY_WORD
                            Range("F" & MY_ROWS).Value = MY_WORD
                            MY_FOUND = ""
                            MY_WORD = ""
'                            GoTo FOUND_1
                        End If
                    End If
                End With
        Next MY_COUNT
'FOUND_1:
    Next MY_ROWS
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Here is another macro that you can try...
VBA Code:
Sub CopyBoldInColumnEtoColumnF()
  Dim X As Long, Txt As String, Rng As Range, V As Variant
  Application.ScreenUpdating = False
  For Each Rng In Range("E1", Cells(Rows.Count, "E").End(xlUp))
    Txt = Rng.Value
    For X = 1 To Len(Rng)
      If Not Rng.Characters(X, 1).Font.Bold Then Mid(Txt, X) = " "
    Next
    For Each V In Split(Trim(Txt), Space(2))
      If Len(Replace(V, " ", "")) Then Cells(Rows.Count, "F").End(xlUp).Offset(1) = Trim(V)
    Next
  Next
  Application.ScreenUpdating = True
End Sub
Note: Existing data is assumed to start in cell E1, output starts at cell F2
 
Upvote 0
Here is another macro that you can try...
VBA Code:
Sub CopyBoldInColumnEtoColumnF()
  Dim X As Long, Txt As String, Rng As Range, V As Variant
  Application.ScreenUpdating = False
  For Each Rng In Range("E1", Cells(Rows.Count, "E").End(xlUp))
    Txt = Rng.Value
    For X = 1 To Len(Rng)
      If Not Rng.Characters(X, 1).Font.Bold Then Mid(Txt, X) = " "
    Next
    For Each V In Split(Trim(Txt), Space(2))
      If Len(Replace(V, " ", "")) Then Cells(Rows.Count, "F").End(xlUp).Offset(1) = Trim(V)
    Next
  Next
  Application.ScreenUpdating = True
End Sub
Note: Existing data is assumed to start in cell E1, output starts at cell F2
that seems to work! many thank :)
But I couldn't make it leave the text in the next cell. it all went up...
if the bold text in E45 i want it to be copied to F45 (and if it has 2 than F45,F46..)
is that possible?
 
Upvote 0
if the bold text in E45 i want it to be copied to F45 (and if it has 2 than F45,F46..)
is that possible?
It depends... what should happen if there are two (or more) bold words in cell E45 and two or more bold works in cell E46?
 
Upvote 0

Forum statistics

Threads
1,215,586
Messages
6,125,686
Members
449,249
Latest member
ExcelMA

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