testing条件格式是否为TRUE VBA并突出显示整行

我试图确定一个特定的单元格是否从条件格式返回TRUE值,然后突出显示整个行(甚至只是一个单元格),如果它返回true。 条件格式是在列B,并希望它突出整个行。

如果条件格式化在列B中返回TRUE,我最终试图在列F中加上数字,但是我可以找出那部分是否可以简单地确定条件格式是否返回true。 我search了每个论坛,网站,例子等,我可以find,但仍然无法使其工作。

我正在运行条件格式来search大量的数据为多个不同的实例。 我可以想出如何做到这一点的唯一方法是作为一个单独的条件格式运行每个条件。 这里是一个子目录的一部分(每个子目录有大约30个条件格式,大约有10个子目录):

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _ "=ISNUMBER(SEARCH(""Acadia Realty Trust "",B1))" Selection.FormatConditions(Selection.FormatConditions.count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .Color = 65535 .TintAndShade = 0 End With Selection.FormatConditions(1).StopIfTrue = False Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _ "=ISNUMBER(SEARCH(""Aimco "",B1))" Selection.FormatConditions(Selection.FormatConditions.count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .Color = 65535 .TintAndShade = 0 End With Selection.FormatConditions(1).StopIfTrue = False Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _ "=ISNUMBER(SEARCH(""Alexandria Real Estate Equities, Inc"",B1))" Selection.FormatConditions(Selection.FormatConditions.count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .Color = 65535 .TintAndShade = 0 End With Selection.FormatConditions(1).StopIfTrue = False 

我只是说,我不能简单地检查与条件格式相同的testing,因为有近300个不同的testing。

更新:

我尝试了吉普build议的内容,然后我在下面创build了多个子类,每个子类都有一个数组,以便适应所有的条件,但是当我这样做时,只会突出显示最后一个数组,而不是所有满足的条件第一潜艇 我使用了与下面build议的@Jeeped相同的代码,但在数组中放置了24个条件,我可以将代码放到11个子文件中,而我的主代码如下所示:

 Public Sub REIT() range("B:B").Select Call A25 Call B25 Call C25 Call D25 Call E25 Call F25 Call G25 Call H25 Call I25 Call J25 Call K25 End Sub 

我最后只是使用两个帮助列来重新search条件和总结我需要的数据,但我仍然有突出问题。

构build一个数组并使用一个循环。 A With … End With语句可以处理对Application.Selection属性的引用。

 Option Explicit Sub makeThreeCFrules() Dim v As Long, vCFRs As Variant vCFRs = Array("=ISNUMBER(SEARCH(""Acadia Realty Trust "", $B1))", vbYellow, _ "=ISNUMBER(SEARCH(""Aimco "", $B1))", vbYellow, _ "=ISNUMBER(SEARCH(""Alexandria Real Estate Equities, Inc"", $B1))", vbYellow) With Selection.EntireRow .FormatConditions.Delete For v = LBound(vCFRs) To UBound(vCFRs) Step 2 With .FormatConditions.Add(Type:=xlExpression, Formula1:=vCFRs(v)) .Interior.Color = vCFRs(v + 1) End With Next v End With End Sub 

你的公式的问题是,你需要锚定列$B1

备用:

如果可以在工作簿中的其他位置放置search项的列表,则可以使用单个“反向通配符查找”来完成此操作。

在这里输入图像说明
Sheet6中的search条件!A2:A4

 Option Explicit Sub makeAllCFrules() Dim v As Long, vCFRs As Variant With Selection.EntireRow .FormatConditions.Delete With .FormatConditions.Add(Type:=xlExpression, _ Formula1:="=SUMPRODUCT(--ISNUMBER(MATCH(""*""&Sheet6!$A$2:$A$4&""*"",$B1, 0)))") .Interior.Color = vbYellow End With End With End Sub 

search条件范围中不包含空行是非常重要的。 如果有的话,你会search一个双通配符,这将包括所有的东西。 当然,提供的子程序可以修改,以便查找search条件的地址,如果它们可能会改变。

reverse_wildcard_results
在selectB1:B99后应用条件格式规则