简体   繁体   English

如何从带有多种颜色的文本并通过Delimiter分隔多个单词的单元格中基于字体颜色提取文本?

[英]How to extract text based on font color from a cell with text of multiple colors and separate multiple words by Delimiter?

How to extract text based on font color from a cell with text of multiple colors 如何从具有多种颜色的文本的单元格中基于字体颜色提取文本

I have a column of data (A). 我有一列数据(A)。 The data in each cell in column (A) is half one color and half another color. (A)列中每个单元格中的数据是一种颜色的一半,另一种颜色的一半。 I have to extract each word separated by delimiter if they are at different places. 如果它们在不同的地方,我必须提取每个由定界符分隔的单词。 I tried the solution in the above link but unable to make changes to suit my purpose as i am a beginner for vba. 我尝试了上述链接中的解决方案,但由于我是vba的初学者,因此无法进行更改以适合我的目的。 please suggest methods to sole this problem. 请提出解决此问题的方法。

(A) Original..........(B) Red (A)原始..........(B)红色

abcdefgh..........abc, gh abcdefgh .......... abc,gh

A User Defined Function (aka UDF) should get you through this. 用户定义的函数(又名UDF)应该可以帮助您完成此任务。

Function udf_Whats_Colored(rTXT As Range, Optional iCLRNDX As Long = 3)
    Dim c As Long, str As String

    For c = 1 To Len(rTXT.Text)
        With rTXT.Characters(Start:=c, Length:=1)
            If .Font.ColorIndex = iCLRNDX Then
                If Not CBool(Len(str)) Or _
                   rTXT.Characters(Start:=c + (c > 1), Length:=1).Font.ColorIndex = iCLRNDX Then
                    str = str & Mid(rTXT.Text, c, 1)
                Else
                    str = str & ", " & Mid(rTXT.Text, c, 1)
                End If
            End If
        End With
    Next c
    udf_Whats_Colored = str

End Function

After considering all of the shades of red that are available, I opted for the simpler solution of .ColorIndex = 3 . 考虑了所有可用的红色阴影后,我选择了.ColorIndex = 3的更简单解决方案。 There is an optional parameter so that you can set your own ColorIndex property number. 有一个可选参数,因此您可以设置自己的ColorIndex属性编号。 If you need more colors, it should be a small matter to swap the code over to the .Font.Color property . 如果需要更多颜色,将代码交换到.Font.Color属性应该是一件小事。

哪个红色字符

The syntax used in the above image in B2 is, 上图中B2中使用的语法是:

=udf_Whats_Colored(A2)

ColorIndex调色板表
ColorIndex Palette Table ColorIndex调色板表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从具有多种颜色文本的单元格中提取基于字体颜色的文本 - How to extract text based on font color from a cell with text of multiple colors 有没有办法使用每个基于文本的单元格作为分隔符将一列分成多列? - Is there a way to separate a column into multiple columns using each text-based cell as a delimiter? 从单元格中具有多种颜色的单元格中提取字体颜色 - Extracting font color from cells with multiple colors in the cell 从单元格中检索完整的富文本数据(单元格内的多种字体颜色/样式) - Retrieving full rich-text data from a cell (multiple font color / styles within cell) 从Excel工作表的单元格中提取多个单词 - extract multiple words from a cell in excel sheet 用于从单元格中提取多次出现的文本 URL 的宏/UDF - Macro/UDF to extract multiple occurances of text URLs from cell Excel:如何根据字体分隔单元格中的数字/文本 styles(下划线、删除线) - Excel: How to separate number/text in cell based on its font styles (underline, strikethrough) 如何根据某些条件从单元格中的文本中提取一行 - How to extract a line from a text in a cell based on certain criteria GemBox 电子表格:一个单元格中的多种字体颜色 - GemBox Spreadsheet : Multiple font colors in one cell Excel:如何提取多个文本 - Excel: How to extract multiple text
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM