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

错误1004:应用程序定义或对象定义错误Excel,excel,runtime-error,vba,Excel,Runtime Error,Vba,我在Excel 2010中有一个子系统,可以将信息复制到单元格中。当我尝试运行它时,我在以下位置收到“应用程序定义或对象定义错误”: With Worksheets("Parameters") .Range(.Cells(line + 3, amountCol), _ .Cells(line + 3, amountCol + 6)).Copy Destination:=amounts End With 这是到错误发生点为止的整个子节点 Dim numLine As Intege

我在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

您能包括代码中定义行、金额和金额的部分吗?什么是
line
?您可以包括声明它的部分并为其赋值吗?
line+3
的整数值是否为1或更多?
amountCol
的值是否为1或更多?
金额
是否声明为具有单元格地址值的
范围
?在现代计算机(32位或更高版本)上,
Dim amountCol作为首选长度
。我已将代码添加到发生错误的位置。@mechanicalnotacrogrammer。我推荐
Long
,因为它更有效;16位变量需要在32位计算机上进行特殊处理。您的问题是
整数
变量的最大值为65535。当行号
超过此值时,宏失败。能否包括定义行、金额和金额的代码部分?什么是
?您可以包括声明它的部分并为其赋值吗?
line+3
的整数值是否为1或更多?
amountCol
的值是否为1或更多?
金额
是否声明为具有单元格地址值的
范围
?在现代计算机(32位或更高版本)上,
Dim amountCol作为首选长度
。我已将代码添加到发生错误的位置。@mechanicalnotacrogrammer。我推荐
Long
,因为它更有效;16位变量需要在32位计算机上进行特殊处理。您的问题是
整数
变量的最大值为65535。当行号
超过此值时,宏失败。