Cookies帮助我们提供我们的服务。 通过使用我们的服务,您同意我们使用Cookie。
提示:其他语言是Google翻译的。 你可以访问 English 版本。
登录
x
or
x
x
注册账户
x

or

如何从Excel中的单元格提取基于字体颜色的文本?

如果您在Excel的每个单元格中都有一些红色文本的数据列表,如下图所示,并且您知道如何仅提取红色文本吗? 现在我将介绍一种快速方法来解决基于Excel中单元格的字体颜色提取文本的难题。

DOC提取物,文本颜色1

根据每个单元格的字体颜色提取文本


箭头蓝色右泡 根据每个单元格的字体颜色提取文本


在Excel中,只能使用定义的函数根据字体颜色提取文本。

1。 按 Alt + F11键 键一起打开Microsoft Visual Basic for Applications窗口。

2。 点击 插页 > 模块 并将随后的VBA代码复制到弹出窗口。

VBA:根据字体颜色提取文本

Function GetColorText(pRange As Range) As String
	'Updateby20141105
	Dim xOut As String
	Dim xValue As String
	Dim i As Long
	xValue = pRange.Text

	For i = 1 To VBA.Len(xValue)

		If pRange.Characters(i, 1).Font.Color = vbRed Then
			xOut = xOut & VBA.Mid(xValue, i, 1)
		End If

	Next

	GetColorText = xOut
End Function

3。 然后保存并关闭对话框,然后选择数据列表旁边的空白单元格,键入此公式 = GetColorText(A1) (A1表示要从中提取文本的单元格),请按 输入 键获取所需的文本,然后拖动自动填充句柄将公式填入所需的范围。

现在你可以看到所有的红色文字被提取。

DOC提取物,文本颜色2

小技巧:在上面的VBA代码中,如果您需要从单元格中提取黑色文本,则可以更改颜色名称 颜色= vbRed 颜色= vbBlack.


相关文章:



推荐的生产力工具

Office Tab

金星1 带上方便的选项卡到Excel和其他Office软件,就像Chrome浏览器,Firefox和新的Internet Explorer。

Kutools for Excel

金星1 惊人! 提高您在5分钟的生产力。 不需要任何特殊技能,每天保存两个小时!

金星1 300 Excel的新功能,让Excel变得简单而强大:

  • 合并单元格/行/列而不丢失数据。
  • 合并和合并多个工作表和工作簿。
  • 比较范围,复制多个范围,将文本转换为日期,单位和货币转换。
  • 按颜色计算,分页小计,高级分类和超级筛选,
  • 更多选择/插入/删除/文本/格式/链接/评论/工作簿/工作表工具...

Excel的Kutools屏幕截图

Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    prudwi · 2 months ago
    The code works well if the red strings are continuous. In case they are separated in the source cell, they are glued to each other in output cell. I mean there is no space in the output if the red text strings are away from each other. Can you please provide a solution for this?
  • To post as a guest, your comment is unpublished.
    Kazam Raza · 2 months ago
    thanks, very interesting code.
  • To post as a guest, your comment is unpublished.
    Roberto · 3 months ago
    dimenticavo io ho Excel 2010
  • To post as a guest, your comment is unpublished.
    Roberto · 3 months ago
    Buonasera, grazie mille un'ottima funzione. Però ho un problema, quando val nel foglio ed inserisco es. = GetColorText (A1) mi restituisce il valore giusto però come riavvio il file mi da errore #VALORE!, se poi clicco 2 volte sopra mi da il valore corretto e così via. che posso fare?
  • To post as a guest, your comment is unpublished.
    JM · 1 years ago
    Hey, Thanks for the Tip. Works great with Red and Black.
    What if I want to parse "Purple"? changing it vbPurple does not work.
    Thanks