VBA找到一个字符串的字体颜色 [英] VBA to find the font color of a string

查看:640
本文介绍了VBA找到一个字符串的字体颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是VBA的新手。我正在为一些文件比较写一个宏。我的要求是如果一个字符串有红色字体,该字符串应该被忽略,迭代和代码应该移动到下一个迭代...我有尝试以下代码。

  Dim compare = {test1,test2,test3,..... 

i = 0

对于j = 1到Ubound(比较)
j = 1

如果compare.Characters(j, Len(compare(i)))。Font.Color<> vbRed然后
'一些代码
结束如果

i = i + 1
下一个

但是在执行过程中我遇到运行时错误424Object Required.Please help me to complete this task



提前感谢

解决方案

说我们有单元格 A1 通过 A4 / p>



然后,这段代码将会找到非红色字符:

  Sub ColorTest()
Dim I As Long,J As Long
对于I = 1到4
对于J = 1到Len(单元格(I,1).Value)
如果单元格(I,1).Characters (开始:= J,长度= 1).Font.Color<> vbRed然后
MsgBox在单元格A处找到非红色&位置& J
结束如果
下一个J
下一个我
结束子


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

However during the execution I am getting runtime error 424 "Object Required.Please help me to complete this task

Thanks in advance.

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆