无法将动态范围复制到另一个工作表

时间:2019-05-21 16:21:30

标签: excel vba

我正在尝试将动态范围的单元格从一张纸复制到另一张纸。在确定范围之前,一切工作进展顺利,直到我尝试将信息从一张纸移到另一张纸上。

我尝试使用.copy.pastevalue = value

我还担心.range(cells(#,#),cells(#,#))仅适用于两个特定的单元格,而不是我想要的它们之间的范围...

Dim i As Integer
Dim h As Integer
Dim j As Integer
Dim LRow As Long
Dim Instance As Long
Dim EndInstance As Long
Dim OvrDue As Long
Dim Rng As Range
Dim RngUp As Range
Dim RngDwn As Range
Dim OutLRow As Long
Dim OutSheet As Worksheet


    'Find last row with information
    LRow = Cells(Rows.Count, 5).End(xlUp).Row
    'MsgBox LRow
    Set OutSheet = Sheets.Add
        OutSheet.Name = "Outgoing"

    i = 4

    Set Rng = Sheet4.Cells(i, 5)

'loop through looking for times when cell above is Different *Store i Instance
'Loop through looking for times when cell below is Different *store i as EndInstance
'   Output Message box only when Cell Below is different.

For i = 4 To LRow

    h = i - 1
    j = i + 1
    Set RngUp = Sheet4.Cells(h, 5)
    Set RngDwn = Sheet4.Cells(j, 5)
    If Rng.Value <> RngUp.Value Then
        Instance = i
    End If
    'check if invoice for the line is past due (AT ALL) *Store i as OvrDue
    If Sheet4.Cells(i, 10).Value < Sheet4.Range("C1").Value Then
        If Sheet4.Cells(j, 10).Value > Sheet4.Range("C1").Value Then
            OvrDue = i
        End If
    End If
    If Rng.Value <> RngDwn.Value Then
        EndInstance = i

        If OvrDue = 0 Then
           Else:
            'create a list of only overdue invoices
            OutLRow = OutSheet.Cells(Rows.Count, 1).End(xlUp).Row
            OutSheet.Range(Cells(OutLRow + 1, 1), Cells(OutLRow + (OvrDue - Instance), 1)).Value = Sheet4.Range(Cells(Instance, 5), Cells(OvrDue, 5)).Value
            MsgBox Instance & OvrDue
        End If
        OvrDue = 0
    End If
    Set Rng = Sheet4.Cells(j, 5)
Next i

使用上面的代码,我当前遇到错误:对象'_Worksheet'的方法'Range'失败。

0 个答案:

没有答案