我写了一个功能比较完整的:
1)对选中的区域中每个单元格进行自动设置;
2)如果单元格有内容,将设置批注与单元格内容相同;
3)如果单元格无内容,将删除批注,如果存在批注的话;
4)增加了对批注的格式(字体字号框体大小)设置;
加了一点注释,以方便LZ自行按需要进行修改。
Sub CommentDeal()
Dim tmpStr As String, m As Range
For Each m In Selection
tmpStr = m.Value
If tmpStr <> "" Then
'添加修改批注内容
If m.Comment Is Nothing Then
m.AddComment tmpStr
Else
m.Comment.Text Text:=tmpStr
End If
'对批注格式进行调整
m.Comment.Visible = True
m.Comment.Shape.Select True
With Selection
.Font.Name = "Times New Roman"
.Font.Size = 10
.Width = 121 '这个数字大小还请LZ自行调整了
.Height = 22
End With
m.Comment.Visible = False
Else
'删除无内容单元格的批注。不需要清除的话,请删除下面一行代码
If Not m.Comment Is Nothing Then m.Comment.Delete
End If
Next m
'清除选中区域所有单元格内容。不需要清除的话,请删除下面一行代码
Selection.ClearContents
End Sub
有疑问,请Hi我或给我发百度消息
GoodLuck!
温馨提示:答案为网友推荐,仅供参考