Excel:如何从条件单元格返回评论

如何将条评论作为单元格返回。

例:

=if(a1=0;insert comment on cell) 

插入评论和显示评论

我找不到任何方式与默认的工作表函数,所以你可能不得不声明你自己的函数 – 这样的:

 Public Function GetComment(rng As Range) as String GetComment = rng.NoteText 'also possible 'GetComment = rng.Comment.Text End Function 

将这个函数保存到一个模块中,所以它可以作为工作表函数访问。

然后使用=if(a1=0;GetComment(A1))返回评论。

编辑:

因为我可能误解了一下 – 这是一个verison,它给调用者单元添加了一个评论,将它的内容设置为给定的评论,并使评论可见。

 Public Function AddCmt(strComment As String) As String Dim rngCaller As Range If TypeName(Application.Caller) Like "Range" Then Set rngCaller = Application.Caller With rngCaller If .Comment Is Nothing Then .AddComment (strComment) Else .Comment.Text strComment End If .Comment.Visible = True End With 'set caller-cell content to given comment AddCmt= strComment End If End Function