更改单元格中部分文本的字体颜色 [英] Change font color for a part of text in cell
本文介绍了更改单元格中部分文本的字体颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的单元格将包含以下值
I have cells which will contain the below value
"Image not allowed|png"
我想单独更改 | png 的颜色,或者... / strong>
I want to change the color of |png alone or whatever comes after "|"
现在我正在尝试使用以下代码更改字体颜色
Now i am trying to change the font color using the below code
Cells(4,2).Font.Color = RGB(255, 50, 25)
它会更改整个单元格字体颜色,是否可以使用VBA更改所选的文本颜色( | png
)
It will change the entire cells font color, Is it possible to change only the selected text color(|png
) using VBA?
推荐答案
这应该是一个好的开始:
This should be a good start :
Sub vignesh()
Dim StartChar As Integer, _
LenColor As Integer
For i = 1 To 5
With Sheets("Sheet1").Cells(i, 1)
StartChar = InStr(1, .Value, "|")
If StartChar <> 0 Then
LenColor = Len(.Value) - StartChar + 1
.Characters(Start:=StartChar, Length:=LenColor).Font.Color = RGB(255, 0, 0)
End If
End With
Next i
End Sub
这篇关于更改单元格中部分文本的字体颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文