VBA中的目标条件格式

我有一个包含15列数据的Excel工作表。 我想检查其中一列,并突出显示一个单元格,如果它低于25,000,000。 只要录制一个macros,我可以做到这一点,它给了我这个代码:

Sub ebitda_check() 'ebitda < 25MM Macro Columns("H:H").Select Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _ Formula1:="=25000000" Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .Color = 255 .TintAndShade = 0 End With Selection.FormatConditions(1).StopIfTrue = False End Sub 

但这并没有说明我想要定位的列可能会在下一次移动或位于不同的列中。 我如何写东西来检查,例如,“如果列标题是”EBITDA“,突出显示25,000,000以下的任何内容”?

像这样的东西:

 Sub ebitda_check() Dim f As Range, sht As Worksheet, rng As Range Set sht = ActiveSheet 'find the header Set f = sht.Rows(1).Find("EBITDA", lookat:=xlWhole) 'if found, format the content below the header If Not f Is Nothing Then Set rng = sht.Range(f.Offset(1, 0), sht.Cells(Rows.Count, f.Column).End(xlUp)) With rng.FormatConditions.Add(Type:=xlCellValue, Operator:=xlLess, _ Formula1:="=25000000") .SetFirstPriority With .Interior .PatternColorIndex = xlAutomatic .Color = 255 .TintAndShade = 0 End With .StopIfTrue = False End With End If End Sub