我在工作簿中有这个小问题。我想通过使用数组公式来简单地编写一个很长的函数。该公式运行良好并产生了预期的结果。但是,在我的 VBA 宏中,我复制,然后进行公式粘贴,然后进行格式粘贴。格式粘贴崩溃:“无法粘贴,因为复制和粘贴区域的大小不同”(或类似)。如果我使用任何其他不是数组公式的公式,这个问题就解决了。
有没有人遇到过这种情况并找到合适的解决方案?我似乎无法在 Google 上找到帮助答案。如果需要,我会发布代码,但它相当简单 ( Row.Copy ... Rows(something, something).PasteSpecial...
) 并且无论如何都可以使用非数组公式。
编辑:代码:
sRapDetail = "rap - détails"
Sheets(sRapDetail).Select
iStart = 17
iFormuleExceptionRNIAC = 13
iFormule1 = 14
iFormule2 = 15
iFormuleExceptionAR = 16
range(Rows(iStart - 1), Rows(1000)).Hidden = False
iLastRow = Cells(65535, "B").End(xlUp).Row
range("A" & iStart & ":AL" & iLastRow).Select
' selection.Borders(xlInsideVertical).LineStyle = xlNone
' selection.Borders(xlEdgeBottom).LineStyle = xlNone
selection.Delete Shift:=xlUp
'RNIAC
Sheets("Zoom0").Select
If Cells(21, "B").Value = "" Or Cells(22, "B").Value = "" Then
iLastRow = 21
Else
iLastRow = Cells(21, "B").End(xlDown).Row
End If
iNbRow = iLastRow - 20
Sheets(sRapDetail).Select
Rows(iFormuleExceptionRNIAC).Select
selection.Copy
range(Rows(iStart), Rows(iStart - 1 + iNbRow)).Select
selection.PasteSpecial xlPasteFormulas
selection.PasteSpecial xlPasteFormats
(是的,我知道使用selection
是丑陋的(或至少在这种情况下),但这是由一位同事写的)