在Excel 2007中使用VBA添加条件格式时停止更改字体颜色

因此,我将条件格式添加到用户使用VBAdynamic创build的一列单元格中。 我遇到的问题是,添加第一个格式后,任何后续格式将更改已格式化单元格的字体颜色。 在单元格中已经有一些条件格式,这些格式是从格式为“0”或“select一个”的主要源复制的,在黄色单元格中是蓝色文本以下是我目前使用的代码:

With Range(Ltrs & 36, Ltrs & 41) .FormatConditions.Add xlExpression, Formula1:="= $" & Ltrs & "$33 <> ""Custom" & OCV + 1 & """" .FormatConditions(.FormatConditions.Count).SetFirstPriority With .FormatConditions(1) .Interior.Color = vbBlack .Font.Color = vbBlack .StopIfTrue = False End With End With With Range(Ltrs & 42, Ltrs & 44) .FormatConditions.Add xlExpression, Formula1:="=AND($" & Ltrs & "$29<>Repack1, $" & Ltrs & "$29<>Repack2)" .FormatConditions(.FormatConditions.Count).SetFirstPriority With .FormatConditions(1) .Interior.Color = vbBlack .Font.Color = vbBlack .StopIfTrue = False End With End With With Range(Ltrs & 45) .FormatConditions.Add xlExpression, Formula1:="=AND($" & Ltrs & "$29<>Repack1, $" & Ltrs & "$29<>Repack2)" .FormatConditions(.FormatConditions.Count).SetFirstPriority With .FormatConditions(1) .Interior.Color = vbBlack .Font.Color = vbBlack .StopIfTrue = False End With End With With Range(Ltrs & 47) .FormatConditions.Add Type:=xlTextString, String:="Enter", TextOperator:=xlContains .FormatConditions(.FormatConditions.Count).SetFirstPriority With .FormatConditions(1) .Interior.Color = 13421823 'Light Red .Font.Color = -14614363 'Dark Red/Brown .StopIfTrue = False End With End With 

这将导致所有带有0的单元格被格式化为红色文本,所有带有“select一个:”的单元格将具有黑色文本,而包含值“Enter”的单元格具有蓝色文本。 奇怪的是(至less对我来说)是内部单元格颜色都是正确的,只是字体颜色是错误的。

尝试这样的地方,其中开始是你想开始条件格式化的字符和长度是你需要格式化的字符数。

范围(“B2”,“H11”)。字符(开始,长度).Font.Size = 14

范围(“B2”,“H11”)。字符(开始,长度).Font.Bold = True

范围(“B2”,“H11”)。字符(开始,长度).Font.Underline = True