当我复制并粘贴时,excel会将单元格引用下移。例如,对行3上的单元格B2的引用变成了对行4上的行B3的引用。
通过剪切和粘贴,这种情况不会发生,对单元格B2的引用仍然是对B2的引用。
我想要剪切和粘贴的行为,但不会丢失原始内容。
我试着录制一个宏,然后按F2、SHIFT-HOME、复制和转义,而excel什么也不记录。但这就是我希望宏做的事情,这样当我复制它时,它就会完美地复制它。
发布于 2014-06-12 03:14:28
经过大量的工作,我得出了以下结论:
Dim formulas() As String
Dim initCopyCol As Integer
Dim initCopyRow As Integer
Dim columns As Integer
Dim rows As Integer
Sub copyFormulaRange()
initCopyCol = Selection.Column
initCopyRow = Selection.row
columns = Selection.columns.Count
rows = Selection.rows.Count
ReDim formulas(1 To columns, 1 To rows)
For i = 1 To columns
For j = 1 To rows
formulas(i, j) = Cells(initCopyRow + j - 1, initCopyCol + i - 1).Formula
Next j
Next i
End Sub
Sub pasteFormulaRange()
Dim initPasteCol As Integer
Dim initPasteRow As Integer
initPasteCol = Selection.Column
initPasteRow = Selection.row
For i = 1 To columns
For j = 1 To rows
Cells(initPasteRow + j - 1, initPasteCol + i - 1).Formula = formulas(i, j)
Next j
Next i
End Sub
https://stackoverflow.com/questions/24163157
复制相似问题