我需要使用VBA拖动一个数组公式并粘贴值,但excel一直崩溃



我正试图为一系列单元格拖动一个数组公式,然后复制/粘贴相应的值。然而,我的特长不断崩溃。基本上,公式转到特定的行,然后将所有值硬粘贴到工作表中。我是VBA的新手,所以请随意剖析我的代码并给出建议。

Dim lastRow1 As Long
lastRow1 = 37
'change i to whatever your starting row is. Cells(i, #), the # indicates the column index
For i = 3 To lastRow1
Cells(i, 10).Value = Cells(i, 6)
Cells(i, 6).FormulaArray = ""array formula"
Cells(i, 6).Copy
Cells(i, 6).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False

下拉:

Range("A6").Select
ActiveCell.FormulaR1C1 = "formula"
Selection.AutoFill Destination:=Range("A6:A" & lastRow1)

复制粘贴值:

Range("A6:A" & lastRow1).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

lastRow函数(lastRow1=fLastRow而不是lastRow1=37(:

Function fLastRow() As Long
fLastRow = 0
If WorksheetFunction.CountA(Cells) > 0 Then
fLastRow = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
End If
End Function

最新更新