错误1004:应用程序定义的或对象定义的错误Excel

我有一个在Excel 2010中的子将信息复制到单元格中。 当我尝试运行它时,出现“应用程序定义或对象定义的错误”:

With Worksheets("Parameters") .Range(.Cells(line + 3, amountCol), _ .Cells(line + 3, amountCol + 6)).Copy Destination:=amounts End With 

这是发生错误的整个子部分。

 Dim numLine As Integer Dim line As Integer Dim allocationType As String Dim allocationRow As Integer Dim specialFund As Integer Dim amountCol As Integer Dim numCol As Integer Dim amounts As Range Dim i As Integer Dim costCol As Integer Dim alloCol As Integer Dim SFcol As Integer SFcol = 38 alloCol = 32 costCol = 34 'set number of allocation lines With Worksheets("Parameters") numLine = .Range(.Cells(3, 18), .Cells(3, 18).End(xlDown)).Count - 1 End With 'set allocation starting point allocationRow = 3 'set the amount starting columng With Worksheets("Parameters") numCol = .Range(.Cells(3, 18), .Cells(3, 18).End(xlToRight)).Count - 1 'look for the starting year For line = 1 To numCol If .Cells(3, 18 + line).Value = Worksheets(wks).Cells(2, costCol) Then amountCol = line + 18 Exit For End If Next line End With 'go through each line, if allocation, add For line = 1 To numLine With Worksheets("Parameters") allocationType = .Cells(3 + line, 18).Value End With 'check if needs to be included If InStr(allocationType, Worksheets("Parameters").Cells(6, 7).Value) Then With Worksheets(wks) 'format the type cell .Range(.Cells(allocationRow, alloCol), .Cells(allocationRow, alloCol + 1)).MergeCells = True .Range(.Cells(allocationRow, alloCol), .Cells(allocationRow, alloCol + 1)).HorizontalAlignment = xlLeft 'check if needs color If InStr(allocationType, "Roads") Then .Range(.Cells(allocationRow, alloCol), .Cells(allocationRow, alloCol + 1)).Interior.ColorIndex = 36 ElseIf InStr(allocationType, "Structures") Then .Range(.Cells(allocationRow, alloCol), .Cells(allocationRow, alloCol + 1)).Interior.ColorIndex = 34 Else 'check if special funding color For specialFund = 3 To Worksheets.Count - 2 If InStr(allocationType, Worksheets(specialFund).Name) Then .Range(.Cells(allocationRow, alloCol), .Cells(allocationRow, alloCol + 1)).Interior.ColorIndex = .Cells(2, SFcol + specialFund).Interior.ColorIndex End If Next End If 'add the allocation type .Range(.Cells(allocationRow, alloCol), .Cells(allocationRow, alloCol + 1)) = allocationType .Range(.Cells(allocationRow, alloCol), .Cells(allocationRow, alloCol + 1)).ShrinkToFit = True 'add the amounts range Set amounts = .Range(.Cells(allocationRow, costCol), .Cells(allocationRow, costCol + 6)) End With 'copy amounts With Worksheets("Parameters") .Range(.Cells(line + 3, amountCol), .Cells(line + 3, amountCol + 6)).Copy Destination:=amounts End With