如何识别红色字体的起始位置? [英] How do I identify the starting position of red font?
本文介绍了如何识别红色字体的起始位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
我试图找到一种方法来识别一串文字中红色字体的起始位置Excel中。 例如,如果我有"ABCDEFG",在井中,并且"B"在井中。是红色的,我想确定红色的"B"是红色的。在
的第二个位置。
任何帮助将不胜感激! 谢谢!
解决方案
也许是这样的......
选项明确
子测试()
Dim rCell As Range
Dim Pos As长
设置rCell = ActiveCell
Pos = GetRedFontPosition(rCell)
MsgBox Pos,vbInformation
End Sub
函数GetRedFontPosition(ByVal目标为范围)为长
Dim i As Long
目标
对于i = 1到Len( .Value)
如果.Characters(i,1).Font.Color = vbRed那么
GetRedFontPosition = i
退出函数
结束如果
下一个i
结束时
GetRedFontPosition = 0
结束功能
注意您还可以使用RGB功能来定义颜色。 以红色为例......
如果.Characters(i,1).Font.Color = RGB (255,0,0)然后希望这会有所帮助!
Hello
I am trying to find a way to identify the starting position of red font in a string of text in excel. For instance, if I have "ABCDEFG" in a well, and the "B" is red, I would like to identify that the red "B" is at the second position.
Any help would be appreciated! Thank you!
解决方案
Maybe something like this...
Option Explicit Sub test() Dim rCell As Range Dim Pos As Long Set rCell = ActiveCell Pos = GetRedFontPosition(rCell) MsgBox Pos, vbInformation End Sub Function GetRedFontPosition(ByVal Target As Range) As Long Dim i As Long With Target For i = 1 To Len(.Value) If .Characters(i, 1).Font.Color = vbRed Then GetRedFontPosition = i Exit Function End If Next i End With GetRedFontPosition = 0 End FunctionNote that you can also use the RGB function to define your color. For red, as an example...
If .Characters(i, 1).Font.Color = RGB(255, 0, 0) ThenHope this helps!
这篇关于如何识别红色字体的起始位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文