How to extract text based on font color from a cell with text of multiple colors

后端 未结 1 1746
再見小時候
再見小時候 2020-12-21 06:57

I have a column of data (A). The data in each cell in column (A) is half one color and half another color. For example, let\'s say the first portion of the character strin

相关标签:
1条回答
  • 2020-12-21 07:36

    You can use this user defined function:

    Function redPart(x As Range) As String
        Dim res As String
        With x
            For i = 1 To Len(.Value)
                ' red = RGB(255, 0, 0)
                If .Characters(i, 1).Font.Color = RGB(255, 0, 0) Then
                    res = res & .Characters(i, 1).Text
                End If
            Next
        End With
        redPart = res
    End Function
    

    just write in cell B1 formula =redPart(A1) and drag it down.

    Result:

    enter image description here

    0 讨论(0)
提交回复
热议问题