首页 > 解决方案 > Excel IF函数基于单元格注释文本

问题描述

我不确定它是否可能,但我想做的是检查 IF 函数中特定字符串的单元格注释文本

IE =IF(MID(CellA.CommentText,3,3) = "XYZ", {True},{False})

标签: excel-formula

解决方案


没有 Excel 公式可以引用没有 VBA 用户定义函数的注释。

要做到这一点,你需要这样的东西:

Public Function GetCellComment(Target As Range) AS Variant
    On Error Resume Next 'In case reference is invalid, no comment exists, etc
    GetCellComment = Target.Cells(1, 1).Comment.Text
End Function

(如果 - 并且当 -当工作簿中的任何单元格发生更改时,您绝对需要重新计算该函数,您可以在 .之前添加该行。但是,过度使用它会使工作簿运行缓慢,因此请谨慎使用)Application.VolatileOn Error Resume Next

然后在 Excel 函数中使用它:

=IF(MID(GetCellComment(CellA), 3, 3) = "XYZ", {True},{False})

推荐阅读