2017-03-03 44 views
-1

我有一个单元格中的彩色文本字符序列。我想根据颜色将其解析为多个单元格,如下所示。颜色重复。我尝试使用本论坛中已发布的一些解决方案,包括解决方案:How to extract text based on font color from a cell with text of multiple colors and separate multiple words by Delimiter?。但是,无法达到我想要的结果。有什么建议么?将Excel电子表格单元格中的多色文本解析为多个单元格?

enter image description here

+0

您需要发布您的代码,并告诉我们,当你运行它“但是,不能达到我想要的结果”发生了什么并没有真正给任何人多去帮助你。 – Sorceri

+0

当然!我也在不断测试解决方案。我会很快做到这一点。 – RanonKahn

+0

另一个选项可能是从'[H2] .Value(11)'或'[H2] .Value(12)' – Slai

回答

2

这看起来没错。

Option Explicit 

Function udf_Color_Piece(rTXT As Range, Optional iNDX As Long = 1) 
    Dim c As Long, seg As Long, clr As Long 

    seg = 0 
    clr = -9 
    udf_Color_Piece = vbNullString 

    For c = 1 To Len(rTXT.Text) 
     With rTXT.Characters(Start:=c, Length:=1) 
      If clr <> .Font.Color Then 
       seg = seg + 1 
       clr = .Font.Color 
       If seg > iNDX Then Exit Function 
      End If 
      If seg = iNDX Then 
       udf_Color_Piece = udf_Color_Piece & .Text 
      End If 
     End With 
    Next c 

End Function 

enter image description here

+0

解析单元格值XML谢谢@Jeped! – RanonKahn

+0

不错的一个Jeeped! – ryguy72

相关问题