添加注释作为公式

Adding a comment as a formula

如何自动对 Excel Sheet 发表评论?是否有公式可以创建 "= Comment("etc")" 之类的评论?

例如,在一个每一行都有简短介绍的专栏中,我认为在每个单元格中添加评论会比长文本更好。

也欢迎其他选择。

要将每个单元格的内容添加到与该单元格关联的评论中,您可以使用 VBA 中的 AddComment 方法:

Sub comment()

Dim ws As Worksheet
Dim rng As Range

Set ws = Worksheets(1)
Set rng = ws.UsedRange

    For Each c In rng.Cells
        c.AddComment.Text c.Formula
    Next c


End Sub

这也将显示非公式单元格内容。如果要确定这是否是实际公式,可以使用带有 application.WorksheetFunction.IsFormula(range(c.address))if 语句来获取布尔值。

希望对您有所帮助。

使用 VBA 的一个简单答案是创建一个 VBA 函数,如下所示:

Option Explicit

Function InsertComment(Stringincell As String, StrinComment As String)
   Application.Caller.ClearComments
   Application.Caller.AddComment StrinComment
   InsertComment = Stringincell
End Function

现在您使用常规 excel 并在单元格中输入 function/formula 以获取您的文本作为评论:

=Comment("String to see in the cell","String you want to see in the comment")