Excel:如何从条件中将注释作为单元格返回

标签 excel comments

如何从条件条件中将注释作为单元格返回。

示例:

=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))返回评论。

编辑:

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

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

关于Excel:如何从条件中将注释作为单元格返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12567167/

相关文章:

visual-studio-code - VS 代码评论面板

java - 问题编码 java->xls

string - VBA excel,比较两个工作簿中的字符串

excel - 如何按特定顺序将 Excel 注释打印到多个工作表?

comments - 有没有办法注释掉代码块?

python - 注释掉 Enthought Canopy 中的代码块

php - 获取 php 方法注释

arrays - 使用变体数组加速每个循环。 Excel VBA

sql-server - SSIS - 将 SQL 查询结果设置为 Excel 连接字符串的变量

string - excel宏来格式化数据