用条件添加相邻单元格值的注释

我没有VBA的经验。 我知道有很多类似这个问题的答案,但是我不能调整任何代码来让它为我工作。

我有一个表中有大量行的Excel表。
A列中有一些值(数字),B列中有他们的笔记(文本)。我想把那些笔记(B列)作为A列中单元格的注释。

但是这里是条件:
A列中的一些单元格已经有了对它们的评论,我不想用笔记replace它们。 所以我需要一个代码,可以跳过这些特定的单元格或合并他们的意见与笔记。

在这里,我的方法为你的问题:

Public Sub addComment() Dim row As Integer Dim oldComment As String 'Set start row row = 1 With Sheets("sheetname") 'Do until "A" cell is blank Do While .Range("A" & row) <> "" 'If "B" cell is not blank If .Range("B" & row) <> "" Then 'If "A" has no comment, set "" to oldComment If .Range("A" & row).Comment Is Nothing Then oldComment = "" 'Else comment is exist Else 'Store that comment to oldComment oldComment = .Range("A" & row).Comment.Text & " " 'Delete comment from cell .Range("A" & row).Comment.Delete End If 'Insert comment for "A" with old if exist .Range("A" & row).addComment (oldComment & .Range("B" & row).Value) End If 'Increase row row = row + 1 Loop End With End Sub