问题描述:假设有两个单元格,分别为源单元格和目标单元格,源单元格中有数据和批注,要怎样把源单元格中的数据和批注引用到目标单元格,而且不改变目标单元格的其他格式,同时目标单元格与源单元格同步更新?
尝试的方法:用选择性粘贴分别粘贴数据和批注,这样不会改变目标单元格的格式,且数据也可同步更新,但是批注就无法同步更新了。
求教了。
------解决方案--------------------------------------------------------
'假设源单元格是A1,目标单元格是B1
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Worksheet_SelectionChange Target
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next
Dim temp As Comment
Application.EnableEvents = False
If Target.Address = "$A$1 " Then
Range( "B1 ").Value = Target.Value
Set temp = Target.Comment
Range( "B1 ").ClearComments
If Not temp Is Nothing Then
Range( "B1 ").AddComment
Range( "B1 ").Comment.Text Target.Comment.Text
End If
End If
Application.EnableEvents = True
End Sub