"运行时错误' 1004':应用程序定义的错误或对象定义的错误"使用Excel VBA中的范围

时间:2016-08-06 11:49:48

标签: excel vba excel-vba

我为VBA编写了以下代码(Excel 2015)。我得到了一个"运行时错误' 1004':应用程序定义的错误或对象定义的错误"在Set Cell(i, j) = Sheets(c).Cells(Cell(i, j))。我试图在" Cell"中重新定义范围。数组作为不同表格中的相同范围。

Dim c As Integer, i As Integer, j As Integer, k As Integer, l As Integer, box As Range, Cell(6 To 24, 3 To 5) As Range

For i = 6 To 24

    For j = 3 To 5

        v = Sheets("Capture").Cells(i, j).Value

        For k = 1 To 376

            For l = 1 To 20

                If Sheets(1).Cells(k, l).Value = v Then

                    Set box = Sheets(1).Cells(k, l)

                End If

            Next l

        Next k

        Set Cell(i, j) = box

    Next j

Next i

For c = 1 To 7

    If Sheets("Capture").Cells(2, 2).Value = c Then

        For i = 6 To 24

            For j = 3 To 5
                ' Error: Application-defined or object-defined error
                Set Cell(i, j) = Sheets(c).Cells(Cell(i, j))

                Sheets("Capture").Cells(i, j).Value = Cell(i, j).Value

            Next j

        Next i

    End If

Next c

1 个答案:

答案 0 :(得分:2)

您需要更改:

Set Cell(i, j) = Sheets(c).Cells(Cell(i, j))

致:

Set Cell(i, j) = Sheets(c).Cells(i, j)