您可以循环遍历范围的每个单元格,以在目标目标中复制和设置每个单元格的值、注释等。这是一个例子。
Sub CopySpecial(p_RangeFrom As String, p_OffsetRow As Integer, p_OffsetColumn As Integer)
Dim l_Row As Integer
Dim l_Column As Integer
Dim thisCell As Range
Dim l_TargetCell As Range
l_Row = Range(p_RangeFrom).Row
l_Column = Range(p_RangeFrom).Column
For Each thisCell In Range(p_RangeFrom)
Set l_TargetCell = Range(Cells(thisCell.Row + p_OffsetRow, thisCell.Column + p_OffsetColumn).Address)
' Copy the text
l_TargetCell.Value = thisCell.Value
' Copy the comment only if we have a comment to copy
If Not thisCell.Comment Is Nothing Then
' Delete any existing comment in the target cell, if any.
' If you don't to this the .AddComment Method below will fail.
If Not l_TargetCell.Comment Is Nothing Then l_TargetCell.Comment.Delete
Call l_TargetCell.AddComment(thisCell.Comment.Text)
End If
' Add more items to copy here, such as color, etc.
Next
End Sub
Sub TestCall()
Call CopySpecial("A1:B2", 3, 3)
End Sub