【发布时间】:2014-07-07 12:57:52
【问题描述】:
所以我认为在 VBA 中创建一组单元格时格式化一组单元格相对简单,尽管我想我错了。我的目标是涂黑一组单元格,除非将某个值输入到不同的单元格中。我遇到的问题是字体的格式由于某种原因不起作用。我什至已经从一个宏中复制了 VBA,但它总是在字体部分出错。填充颜色应为黑色,但字体部分引发错误:“应用程序定义或对象定义错误” 下面是宏录制器生成的代码(添加了我的公式),如果我在成功录制后尝试运行它,实际上会失败:
Range(Cells(35, 9 + (11 * (Range("OptionCount").Value + 1))), Cells(40, 9 + (11 * (Range("OptionCount").Value + 1)))).Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$" & Ltrs & "$33 <>" & """Custom" & Range("OptionCount").Value & """"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Font 'Error Here
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
End With
我能想到的唯一引起问题的可能是单元格上已经有超过 3 种条件格式,但如果是这种情况,我会认为填充颜色也不起作用,但确实如此。
【问题讨论】:
标签: vba excel excel-2007 conditional-formatting