Excel VBA - 范围类的自动填充方法失败

时间:2016-05-23 16:40:22

标签: excel vba excel-vba

我尝试自动填充变量,但我得到"范围类的自动填充方法失败"。

以下是有问题的代码:

    Dim lastRow As Long
Dim lastRow2 As Long
    lastRow = Range("A" & Rows.Count).End(xlUp).Row
    lastRow2 = Range("U" & Rows.Count).End(xlUp).Row

    'change where this is accordingly

'Delete columns
   ActiveSheet.Range("C1,D1,F1,G1,H1,I1,L1,M1,R1,S1,V1,W1,Y1,Z1,AA1,AB1,AE1,AF1").EntireColumn.Delete


    Columns("J:J").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

    Range("E10, T10").Value = "Full Name"
    Range("E11").Formula = "=CONCATENATE(C11 , "" "" , D11)"
    Range("E11").AutoFill Destination:="E11:" & lastRow  'THIS LINE THROWS THE ERROR

这里有什么问题?

1 个答案:

答案 0 :(得分:3)

您需要确保将E11:E[lastRow]声明为范围:

Range("E11").AutoFill Destination:=Range("E11:E" & lastRow)