简体   繁体   English

条件格式-突出显示公式不同的单元格?

[英]Conditional Formatting - highlight cells where formula is different?

Is there a way via Conditional Formatting (preferably no VBA, but if it's a must , then I'm open to it), to highlight a cell where the formula "idea" is different than the cell above? 是否可以通过条件格式设置(最好是没有VBA,但是如果必须使用 VBA,那么我可以接受),以突出显示公式“ idea”与上面的单元格不同的单元格?

I have a column of formulas, but have to manually edit a few of those. 我有一列公式,但是必须手动编辑其中一些。 I'd like to have those manually edited formulas highlighted, so when I change the formula for the other cells, I know which cell to skip when updating that column. 我想突出显示那些手动编辑的公式,因此当我更改其他单元格的公式时,我知道更新该列时要跳过哪个单元格。

For example, here's my column and formulas: 例如,这是我的专栏和公式:
在此处输入图片说明

I'd like to have B5 highlighted yellow, since the formula is different. 我希望B5突出显示为黄色,因为公式不同。

I've tried using =FORMULATEXT($B3)<>FORMULATEXT($B2) but that doesn't work, since it's looking at the literal formula text...in which has they're always different. 我试过使用=FORMULATEXT($B3)<>FORMULATEXT($B2)但这不起作用,因为它正在查看文字公式文本...在其中它们始终是不同的。 ( =FORMULATEXT(B3)=FORMULATEXT(B2) will always be FALSE since the formula is technically changing, despite it being the same "idea"). (由于公式在技术上进行了更改,尽管它是相同的“想法”,但=FORMULATEXT(B3)=FORMULATEXT(B2)始终为FALSE )。

I could also perhaps use =LEN($B3)<>LEN($B2) but that would have a false positive when the row changes from 9 to 10 , and again from 99 to 100 ... 我也许也可以使用=LEN($B3)<>LEN($B2)但是当行从9变为10 ,然后又从99变为100时,它会产生误报。

The other option would, of course, just be to work in an IF() statement to clarify why I'm doing a different formula, ie =IF(ROW()=5,A5+A4+A2+A1,A5+A4) and use that...but there's no real logic for why I have to edit manually I could work in - which is why I'd just like a nice visual reminder on those random cells that the formula isn't like the others. 当然,另一个选择就是在IF()语句中工作,以阐明为什么我要使用不同的公式,即=IF(ROW()=5,A5+A4+A2+A1,A5+A4)并使用它...但是没有真正的逻辑可以说明为什么我必须手动编辑才能工作-这就是为什么我只想在这些随机单元格上很好地视觉提醒该公式与其他单元格不同。

Edit: Quick note that the above formulas are way simplified. 编辑:快速的注意,上面的公式简化方式 My actual ones are a little complex. 我的实际情况有些复杂。 I'm looking for a general answer to this too. 我也在寻找对此的一般答案。 Just thinking for my purposes, I could maybe do a check that if the formula has more than two + in it, highlight the cell. 只是在想我的目的,我可能会做一个检查,如果公式有两个以上+在里面,高亮显示该单元。 ...but I'm interested in a general way to solve this type of issue that could apply more broadly. ...但是我对解决这种类型的问题感兴趣,这种方法可以更广泛地应用。

Here's another option for UDF: 这是UDF的另一个选择:

Function findDifferent(Rng As Range) As Boolean

findDifferent = Not (Rng.FormulaR1C1 = Rng.Offset(-1).FormulaR1C1 Or Rng.FormulaR1C1 = Rng.Offset(1).FormulaR1C1)
End Function

在此处输入图片说明

Here's a quick VB aided solution I came up with. 这是我想到的一个快速的VB辅助解决方案。 If I add a comment to the special cells (which I do to explain the formula/why it's different), I can check for a comment then highlight it. 如果我在特殊单元格中添加了注释(我会解释该公式/为什么与众不同),则可以检查注释,然后突出显示它。

Add this function to the workbook: 将此功能添加到工作簿中:

Function has_Comment(cel As Range) As Boolean
has_Comment = False
If cel.Comment.Text <> "" Then
    has_Comment = True
End If
End Function

Then a simple Conditional Formatting formula of: 然后是一个简单的条件格式公式:

=has_comment(B2)

That works, and is relatively simple. 那行得通,而且相对简单。

Edit: I found also you can do this, which doesn't rely on a comment. 编辑:我发现您也可以执行此操作,它不依赖评论。 Just points out an Inconsistency Error . 只是指出了Inconsistency Error

Function has_inconsistency(cel As Range) As Boolean
has_inconsistency = False
If cel.Errors.Item(xlInconsistentFormula).Value = True Then
    has_inconsistency = True
End If
End Function

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM