我正在尝试编写一个VBA宏以应用条件格式,该条件格式将执行以下操作:
如果当前选择的单元格不等于右侧的单元格,请更改填充颜色。到目前为止,我有这个:
Sub Macro8()
'
' Macro8 Macro
'
' Keyboard Shortcut: Ctrl+e
'
Cells.FormatConditions.Delete
Range("G17:J17").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlNotEqual, _
Formula1:="=$K$17"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent5
.TintAndShade = 0.599963377788629
End With
Selection.FormatConditions(1).StopIfTrue = True
End Sub
问题在于范围("G17:J17")
(它是一个合并的单元格)和公式("$K$17")
。
应该是Range("G$CurrentRow:J$CurrentRow")
,Formula1:="=$K$CurrentRow"
但我只是不知道语法。
很抱歉这个笨拙的问题,但是我是PLC程序员,而不是精通Excel的人。在此先感谢您的帮助:)
Range("G17:J17")
应该activeCell.offset(0,1)
假设您正在G列中选择任何单元格。
如果不这样做,则可能需要进行调整-查找ActiveCell()属性-它基本上将当前激活的单元格作为Range()
对象返回
公式可以是 "=$K$" & activecell.row
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句