2

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

例子:

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

插入评论并显示评论

4

1 回答 1

7

我找不到使用默认工作表函数的任何方法,因此您可能必须为此声明自己的函数 - 如下所示:

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

将此函数保存到模块中,以便作为工作表函数访问。

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

编辑:

因为我可能误解了一点 - 这是一个版本,它向调用者单元格添加评论,将其内容设置为给定评论并使评论可见。

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
于 2012-09-24T15:03:40.510 回答