添加注释作为公式

问题描述 投票:0回答:3

如何在 Excel 工作表上自动添加注释?是否有一个公式可以创建像

"= Comment("etc")"
这样的评论或其他?

例如,在每行都有简短介绍的列中,我认为注释比每个单元格中的长文本更好。

也欢迎其他替代方案。

excel excel-formula comments
3个回答
4
投票

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

Option Explicit

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

现在您使用常规 Excel 并在单元格中输入函数/公式以获取文本作为注释:

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

1
投票

要将每个单元格的内容添加到与该单元格相关的注释中,您可以使用 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

这还将显示非公式单元格内容。如果你想确定这是否是一个实际的公式,可以使用

if
语句和
application.WorksheetFunction.IsFormula(range(c.address))
来获取布尔值。

希望有帮助。


0
投票
=LET(
Comment1,
"N() is an ok way to insert a comment."

Comment2,
"If your version of Excel has the new LET() function, there's a much easier way.",

SumA1A4,
SUM(A1:A4),

\0,
"This should also allow comments but I've not tested it (nor tested if you can do \0 multiple times)",

LongComment,CONCATENATE(
"Note though that individual strings need to be <255 characters, so if you need LONG comments",
"you can do it this way."
),

LastComment,
"Reminder that you still need the last entry of LET() to be what you're 
returning",

SumA1A4)
© www.soinside.com 2019 - 2024. All rights reserved.