VBA 查找字符串的字体颜色 [英] VBA to find the font color of a string
本文介绍了VBA 查找字符串的字体颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 VBA 新手..我正在编写一些文件比较的宏..我的要求是,如果字符串具有红色字体,则迭代时应忽略该字符串,并且代码应移至下一次迭代..我有尝试了以下代码.
I am new to VBA..I am writing a macro for some file comparison..My requirement is if a string has red color font,that string should be ignored for iteration and code should move to next iteration..I have tried the following code.
Dim compare = {"test1","test2","test3",.....etc}
i=0
For j=1 to Ubound(compare)
j=1
If compare.Characters(j,Len(compare(i))).Font.Color <> vbRed Then
' Some Code
End If
i=i+1
Next
但是在执行过程中我收到运行时错误 424Object Required. Please help me to complete this task
However during the execution I am getting runtime error 424 "Object Required.Please help me to complete this task
提前致谢.
推荐答案
假设我们有单元格 A1 到 A4 像:
Say we have cells A1 thru A4 like:
然后这段代码会找到非红色字符:
Then this code will find the non-red characters:
Sub ColorTest()
Dim I As Long, J As Long
For I = 1 To 4
For J = 1 To Len(Cells(I, 1).Value)
If Cells(I, 1).Characters(Start:=J, Length:=1).Font.Color <> vbRed Then
MsgBox "non-red found at cell A" & I & " position " & J
End If
Next J
Next I
End Sub
这篇关于VBA 查找字符串的字体颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文