Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel VBA:文本下方的条件格式单元格_Excel_Vba_Formatting_Conditional Statements - Fatal编程技术网

Excel VBA:文本下方的条件格式单元格

Excel VBA:文本下方的条件格式单元格,excel,vba,formatting,conditional-statements,Excel,Vba,Formatting,Conditional Statements,我有一个包含表格式数据的原始数据。如果任何单元格值包含文本“紧急”,则需要突出显示连续的6行,该文本可以出现在单元格的任何位置 我已经写了一个代码,但没有为我工作。这里我用“J”列硬编码。但是,我的字符串可以出现在任何列中 With Cells .FormatConditions.Add Type:=xlExpression, Formula1:= _ "=ISNUMBER(SEARCH(""Urgent*"",$J1))" With .FormatCondi

我有一个包含表格式数据的原始数据。如果任何单元格值包含文本“紧急”,则需要突出显示连续的6行,该文本可以出现在单元格的任何位置

我已经写了一个代码,但没有为我工作。这里我用“J”列硬编码。但是,我的字符串可以出现在任何列中

    With Cells
    .FormatConditions.Add Type:=xlExpression, Formula1:= _
      "=ISNUMBER(SEARCH(""Urgent*"",$J1))"
    With .FormatConditions(.FormatConditions.Count)
        .SetFirstPriority
        With .Interior
            .PatternColorIndex = xlAutomatic
            .Color = 7405514
            .TintAndShade = 0
        End With
        StopIfTrue = False
    End With

!![excel]

请注意,
条件格式是不稳定的。当你说你的字符串可以出现在任何地方?你到底是什么意思?随便什么地方,还是第一排?这真的很重要,因为对电子表格中的所有单元格进行重新计算的易失性函数将变得太慢。我正在通过宏代码从透视表填充两个表,标题位于第27行和第40行,其中“紧急”可以来自“E:M”列的任何位置。是否可以通过宏代码获取相同的标题。像查找紧急列号和使用偏移量一样,我们可以为下面的6个单元格着色<代码>设置rFind=.Cells(1,1).查找(“紧急*”,LookIn:=xlValues,LookAt:=xlWhole).范围(.Cells(28,rFind.Column),.Cells(28+5,rFind.Column))…Interior.ColorIndex=6