How to copy the highlighted text from ColumnA to ColumnB, ColumnC

SarahDetroja

New Member
Joined
May 13, 2020
Messages
18
Office Version
  1. 2013
Platform
  1. Windows
Hello There,

I want to copy the highlighted text from one column to other columns.

There are two options.
1) Highlighted text is "BOLD"
2) Highlighted text is "COLORED"

Ideal two separate solution each for "Bold" and "Color"
If either of one is not possible then please give any one solution.

Note1: I was told it's not possible using formula
Note2: In case of color, it can be hardcoded into the code so Red, Blue, Green (Even Hexadecimal). The only thing each color text should be copied to separate column
 

Attachments

  • Option1_Bold.png
    Option1_Bold.png
    45.2 KB · Views: 15
  • Option2_Color.png
    Option2_Color.png
    30.8 KB · Views: 14

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi and welcome to MrExcel

I provide you the macro to extract the bold texts.
I hope someone else provides the second macro.

VBA Code:
Sub Extract_Bold_Text()
  Dim a As Variant, b As Variant, c As Range
  Dim i As Long, j As Long, lr As Long, nMax As Double
  Dim m As String, una As Boolean, col As Long
  '
  lr = Range("A" & Rows.Count).End(3).Row
  nMax = Evaluate("MAX((LEN(A2:A" & lr & ")-LEN(SUBSTITUTE(A2:A" & lr & ","" "",""""))))") + 1
  ReDim b(1 To lr, 1 To nMax + 1)
  '
  For Each c In Range("A2:A" & lr)
    col = 1
    una = False
    i = i + 1
    For j = 1 To Len(c)
      m = Mid(c, j, 1)
      If c.Characters(j, 1).Font.Bold Then
        b(i, col) = b(i, col) & m
        una = True
      Else
        If una = True Then
          col = col + 1
          una = False
        End If
      End If
    Next j
  Next c
  Range("B2").Resize(lr, nMax).Value = b
End Sub
 
Upvote 0
Hi DanteAmor,

You are a master class. It works perfectly. Thank you very much.

I am not sure about that. It would be great if you can help.

Thanks
Sarah
 
Upvote 0
Hi DanteAmor,

Please don't worry now about color. Thank you very much again for your kind support.

I have noticed you normally the first to help especially new member which I am sure being appreciated by everyone.

Thanks again.
 
Upvote 0
News for you, I provide the second macro

VBA Code:
Sub Extract_Color_Text()
  Dim a As Variant, b As Variant, c As Range
  Dim i As Long, j As Long, lr As Long, nMax As Double
  Dim m As String, una As Boolean, col As Long
  '
  lr = Range("A" & Rows.Count).End(3).Row
  nMax = Evaluate("MAX((LEN(A2:A" & lr & ")-LEN(SUBSTITUTE(A2:A" & lr & ","" "",""""))))") + 1
  ReDim b(1 To lr, 1 To nMax + 1)
  '
  For Each c In Range("A2:A" & lr)
    col = 1
    una = False
    i = i + 1
    For j = 1 To Len(c)
      m = Mid(c, j, 1)
      If c.Characters(j, 1).Font.Color <> vbNormal Then
        b(i, col) = b(i, col) & m
        una = True
      Else
        If una = True Then
          col = col + 1
          una = False
        End If
      End If
    Next j
  Next c
  Range("B2").Resize(lr, nMax).Value = b
End Sub

In case you have bold text or colored text in the same cell:

VBA Code:
Sub Extract_BC_Text()
  Dim a As Variant, b As Variant, c As Range
  Dim i As Long, j As Long, lr As Long, nMax As Double
  Dim m As String, una As Boolean, col As Long
  '
  lr = Range("A" & Rows.Count).End(3).Row
  nMax = Evaluate("MAX((LEN(A2:A" & lr & ")-LEN(SUBSTITUTE(A2:A" & lr & ","" "",""""))))") + 1
  ReDim b(1 To lr, 1 To nMax + 1)
  '
  For Each c In Range("A2:A" & lr)
    col = 1
    una = False
    i = i + 1
    For j = 1 To Len(c)
      m = Mid(c, j, 1)
      If c.Characters(j, 1).Font.Bold Or _
         c.Characters(j, 1).Font.Color <> vbNormal Then
        b(i, col) = b(i, col) & m
        una = True
      Else
        If una = True Then
          col = col + 1
          una = False
        End If
      End If
    Next j
  Next c
  Range("B2").Resize(lr, nMax).Value = b
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,992
Messages
6,175,822
Members
452,672
Latest member
missbanana

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