我有一张 Excel,一张表上有传入数据,另一张表上有代码描述,我想自动创建一个注释来显示传入代码的描述,或者这可能吗。
前任。
"sheet 1" -------------------
serial | Symptom Code |"Comment Box" |
xx1234 | LX1, LC45 ------ |Machine Broken |
|Physical Damage |
-------------------
"sheet 2"
Code | Description
LX1 | Machine Broken
LC45 | Physical Damage
希望这是一个很好的例子,我正在寻找我的声誉不够高,无法插入图片,如果你能帮助我非常感谢
答案1
说工作表1就好像:
和工作表2就好像:
然后,以下宏将查找描述并将其作为注释添加到乙列单元格工作表1
Sub CommentMaker()
Dim sh1 As Worksheet, sh2 As Worksheet, N1 As Long, N2 As Long
Dim s1 As String, s2 As String
Dim i1 As Long, i2 As Long
Set sh1 = Sheets("Sheet1")
Set sh2 = Sheets("Sheet2")
N1 = sh1.Cells(Rows.Count, "A").End(xlUp).Row
N2 = sh2.Cells(Rows.Count, "A").End(xlUp).Row
For i1 = 2 To N1
s1 = sh1.Cells(i1, "B").Text
For i2 = 2 To N2
s2 = sh2.Cells(i2, "A").Text
If s1 = s2 Then
sh1.Cells(i1, "B").ClearComments
sh1.Cells(i1, "B").AddComment sh2.Cells(i2, "B").Text
End If
Next i2
Next i1
End Sub