用大写字母更改单词的颜色 [英] Change colour of words with capital letter
本文介绍了用大写字母更改单词的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的桌子上有很多单词,需要找到带有大写字母的单词并更改其颜色.例如:
I have a table with lots of word and need find words with capital letter and change its colour. For example:
A1: event
A2: Event
A3: Happy day
- ,并且应该在A2和A3中将单词的颜色更改为红色,但在A3中只是"Happy"单词.我尝试解决条件格式问题,但失败了.:)(也许是VBA吗?)
感谢您的帮助.
推荐答案
我可能会跳过正则表达式,只检查与第一个字符的ucase等效项(这只是一个猜测,但我认为它会比使用正则表达式).像这样:
I would probably skip the regex and just check against the ucase equivalent of the first character (this is just a guess, but I think it will be faster than using regex also). Like this:
Sub Capitalize()
Dim sheet As Worksheet
Dim cell, range As range
Dim results() As String
Dim pos As Integer
Set sheet = ActiveSheet
Set range = sheet.range("a1", sheet.range("a" & Rows.Count).End(xlUp))
For Each cell In range
pos = 1
results = Split(cell)
'if first char is upper then set color
For Each r In results
If Left(r, 1) = UCase(Left(r, 1)) Then
cell.Characters(pos, Len(r) + 1).Font.Color = vbRed
End If
pos = pos + Len(r) + 1
Next
Next
End Sub
这篇关于用大写字母更改单词的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文