在我的工作簿中,有一个名为" Form"的工作表,在单元格B32中有一条注释说明需要输入数据 - 但是在数据输入后,注释仍然存在,这很烦人。
如何在输入数据时隐藏 评论 ,如果单元格为空,则取消隐藏?
答案 0 :(得分:1)
您应该将以下代码添加到您的"表格"工作表模块,用于Worksheet_Change
事件。
<强>代码强>
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Comm As Comment
If Not Intersect(Target, Range("B32")) Is Nothing Then
Set Comm = Target.Comment ' set the comment
If Target.Value <> "" Then ' if cell is not empty
Comm.Delete ' delete the comment
Else
Comm.Visible = False ' hide the comment
End If
End If
End Sub
答案 1 :(得分:1)
您可能想要使用此代码
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Comm As Comment
If Not Intersect(Target, Range("B32")) Is Nothing Then
Set Comm = Target.Comment ' set the comment
If Comm Is Nothing Then Exit Sub
If Target.Value <> "" Then
Comm.Visible = False ' hide the comment
Application.DisplayCommentIndicator = xlNoIndicator ' also hide the indicator (unfortunately for the whole application)
Else
Comm.Visible = True ' hide the comment
Application.DisplayCommentIndicator = xlCommentAndIndicator
End If
End If
End Sub
答案 2 :(得分:1)