我需要帮助。我正在做报告并在单元格上插入注释。如何使用具有使用vba或公式注释的特定值来计算excel范围内的单元格?
答案 0 :(得分:1)
这是一种方法。它遍历您在范围内传递的每个单元格,并检查是否有注释。如果是这样,它会将其添加到计数器中。如果在大范围内使用,这可能会相当昂贵,但至少应该让你开始:
添加到常规模块:
Function CommentCounter(rng As Range) As Integer
Dim cell As Range
Dim counter As Integer
Dim currentComment As String
For Each cell In rng
On Error Resume Next
currentComment = cell.Comment.Text
If Len(currentComment) > 0 Then counter = counter + 1
currentComment = ""
Next cell
CommentCounter = counter
End Function
刚刚看到关于具有特定值和评论的部分。这应该让你去:
Function CommentCounter(rng As Range) As Integer
Dim cell As Range
Dim counter As Integer
Dim currentComment As String
Dim specificValue As String
specificValue = "Something Specific"
For Each cell In rng
On Error Resume Next
currentComment = cell.Comment.Text
If cell.Value = specificValue And Len(currentComment) > 0 Then counter = counter + 1
currentComment = ""
Next cell
CommentCounter = counter
End Function
答案 1 :(得分:0)
=COUNTIF(A:A;"comment")
其中A:A指定您要检查A的整个列而不是A:A,您也可以使用A1:A3,这意味着检查A1,A2和A3。
编辑:
如果你想用评论来计算单元格(不是用单词"评论"),我建议你做以下几点:
=COUNT(A1:A3) - COUNTBLANK(A1:A3)