本文介绍了使用公式格式化Excel单元格中的文本子集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在Excel中使用公式构建了字符串.举例
I Have built a string using a formula in excel. as an example
所需文字为:
(粗体文本实际上是某种颜色,如红色)
(where the bold text would actually be some color like red)
是否可以在Excel中执行此操作(更改部分文本格式).
Is there a way to do this in Excel (change partial text formatting) .
我尝试过一个公式...(不起作用)
I Have tried a formula... (Not working)
Function formatText(InText As Range)
'Set font color
InText.Characters(1.5).Font.Color = Red
'InText.Characters((InStr(1, ":", InText) + 1), (Len(InText) - InStr(1, ":", InText))).Font.ColorIndex = 3
End Function
推荐答案
您发布的带有工作的函数,当且仅当
- 它是从
Sub
调用的(即,正如其他人提到的那样,而不是作为UDF)
- It is called from a
Sub
(ie, as other have mentioned, not as a UDF)
还有
-
InText
范围中包含的值是字符串常量. (这是我回答的重点)
- the value(s) contained in range
InText
are string constants. (This is the main point of my answer)
对于InText
范围内包含公式的任何单元格,它将不起作用.抱歉,您无法格式化公式返回的字符串的 part .
It will not work for any cells in range InText
containing a formula. AFAIK you cannot format part of a string returned by a formula.
顺便说一句,我很想被证明是错误的!
BTW I would love to be proved wrong on this!
这篇关于使用公式格式化Excel单元格中的文本子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!