在工" />
乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > <em>Excel</em> 2010怎么自动添加批注?-excel 自动插入批注,excel怎

<em>Excel</em> 2010怎么自动添加批注?-excel 自动插入批注,excel怎

作者:乔山办公网日期:

返回目录:excel表格制作


选中要批注的单元格,然后按住“Alt”键不放,再分别按一次“I”键后再按一次“M”键。

在工作表标签上击右键,查看代码,在VBE窗口中点“插入”,7a686964616fe4b893e5b19e337模块,

在模块代码窗口中粘贴以下代码,然后按ALT+F8运行之,即可

Sub 添加批注()
For i = 1 To 2 '注:列遍历
For j = 4 To Cells(65536, i).End(3).Row '注:行遍历
If Cells(j, i) <> "" Then '检测非空
Dim a
a = ""
For K = 2 To [e65536].End(3).Row '遍历E列区域
If Cells(K, 5) = Cells(j, i) Then '比对数据
a = a & CStr(Cells(K, 6)) '获取对应F列的值存入变量a。
On Error Resume Next '容错
    Cells(j, i).ClearComments '若有批注,先行删除
    Cells(j, i).AddComment '添加批注
    Cells(j, i).Comment.Visible = False '批注隐藏
    Cells(j, i).Comment.Text Text:=a '批注内容
    End If
Next
End If
Next
Next
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
Dim d As String, s As String, r As Integer, s1 As String
r = Target.Row
d = Target.Address
s1 = Application.WorksheetFunction.VLookup(Cells(r, 1), Sheet1.Range("a:b"), 2, 0) & Target.Value
s = Application.WorksheetFunction.VLookup(s1, Sheet2.Range("a:b"), 2, 0)
If s <> "" Then
Range(d).ClearComments
Range(d).AddComment
Range(d).Comment.Visible = False
Range(d).Comment.Text Text:=s
End If
If Target.Value = "" Then
Range(d).ClearComments
End If
End Sub




'给所有满足条件的单元格添加批注
Sub 添加批注()
Dim I, J, X, Y As Long
Cells.ClearComments
X = ActiveCell.SpecialCells(xlLastCell).Row
Y = ActiveCell.SpecialCells(xlLastCell).Column
For I = 2 To X Step 2: For J = 1 To Y
Cells(I, J).Select
Selection.AddComment
Selection.Comment.Text Cells(I - 1, J) & vbCrLf & Cells(I, J)
Next J: Next I
End Sub

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网