范围 class 的自动填充方法失败,我错过了什么?
AutoFill method of range class failed, what am I missing?
我正在尝试将一行公式自动填充到它的前一行。
我在 excel 2010 年。我知道我在自动填充功能中使用的范围是正确的范围,我通过添加 select 功能并通过行以确保 select 正确。
Sub NewIC()
Dim v As Range, newV As Range, oldVRow As Range, newVRow As Range
Dim s As Range
Dim dc As Range
With Sheets("Charts").Cells
'Inserting name into Vios
Set v = .Find("Vios", LookIn:=xlValues)
If Not v Is Nothing Then
v.Select
ActiveCell.Offset(4, 0).Select
With Selection.EntireRow.Insert(xlShiftDown, xlFormatFromRightOrBelow)
Set newV = ActiveCell
Range("T1").Copy newV
newV.Font.Bold = True
End With
End If
'Dragging up formulas
Set oldVRow = Range(newV.Offset(-1, 1), newV.Offset(-1, 8))
Set newVRow = Range(newV.Offset(0, 1), newV.Offset(0, 8))
oldVRow.Select
newVRow.Select
newVRow.AutoFill Destination:=oldVRow, Type:=xlFillDefault
End With
End Sub
所有代码都运行到最后一行。它将正确的单元格设置为 newV,设置正确的范围,但我收到错误
Run-time error '1004' AutoFill method of Range class failed
修改:
Set newVRow = Range(newV.Offset(0, 1), newV.Offset(0, 8))
包括上面的行:
Set newVRow = Range(newV.Offset(-1, 1), newV.Offset(0, 8))
并更改:
newVRow.AutoFill Destination:=oldVRow, Type:=xlFillDefault
至:
oldVRow.AutoFill Destination:=newVRow, Type:=xlFillDefault
你不需要使用所有这些Select
:
'oldVRow.Select ' comment this row
'newVRow.Select ' comment this row
我正在尝试将一行公式自动填充到它的前一行。
我在 excel 2010 年。我知道我在自动填充功能中使用的范围是正确的范围,我通过添加 select 功能并通过行以确保 select 正确。
Sub NewIC()
Dim v As Range, newV As Range, oldVRow As Range, newVRow As Range
Dim s As Range
Dim dc As Range
With Sheets("Charts").Cells
'Inserting name into Vios
Set v = .Find("Vios", LookIn:=xlValues)
If Not v Is Nothing Then
v.Select
ActiveCell.Offset(4, 0).Select
With Selection.EntireRow.Insert(xlShiftDown, xlFormatFromRightOrBelow)
Set newV = ActiveCell
Range("T1").Copy newV
newV.Font.Bold = True
End With
End If
'Dragging up formulas
Set oldVRow = Range(newV.Offset(-1, 1), newV.Offset(-1, 8))
Set newVRow = Range(newV.Offset(0, 1), newV.Offset(0, 8))
oldVRow.Select
newVRow.Select
newVRow.AutoFill Destination:=oldVRow, Type:=xlFillDefault
End With
End Sub
所有代码都运行到最后一行。它将正确的单元格设置为 newV,设置正确的范围,但我收到错误
Run-time error '1004' AutoFill method of Range class failed
修改:
Set newVRow = Range(newV.Offset(0, 1), newV.Offset(0, 8))
包括上面的行:
Set newVRow = Range(newV.Offset(-1, 1), newV.Offset(0, 8))
并更改:
newVRow.AutoFill Destination:=oldVRow, Type:=xlFillDefault
至:
oldVRow.AutoFill Destination:=newVRow, Type:=xlFillDefault
你不需要使用所有这些Select
:
'oldVRow.Select ' comment this row
'newVRow.Select ' comment this row