2012-09-24 20 views
2

如何從條件單元格返回評論。Excel:如何作爲單元格從條件返回評論

例子:

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

插入註釋,顯示評論

+1

你不能用工作表函數做到這一點。您可以使用VBA宏執行此操作.http://msdn.microsoft.com/en-us/library/office/aa221696(v = office.11​​).aspx –

回答

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))返回評論。

編輯:

因爲我可能誤會了一點 - 這裏是一個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 
+0

您是對的,您只能通過VBA以編程方式編輯註釋。 – danielpiestrak