为什么我不断收到运行时错误6溢出错误消息?

时间:2019-01-11 17:47:29

标签: excel vba loops

所以我试图以某种方式本质上过滤我的数据集。这样做可能有更好的方法,而我可能会使事情复杂化,因此,在这种情况下,请随时提出任何想法。因此,基本上我正在过滤我的数据集。但是,基于该过滤器,我将仅基于条件获取一些特定数据。因此,我将隐藏不符合该条件的数据,如下所示:

If Sheet1.Cells(i, 11) = StandardW And Sheet1.Cells(i, 32) > Date1 Then
    Rows("i:i").Select
    Selection.EntireRow.Hidden = True

然后,我将复制数据集的第一列,并将其粘贴到其他位置以供以后使用。但是,由于某种原因,我不断收到“运行时错误6溢出错误消息”。不知道为什么。有任何想法吗?如上所述,也许有一种更简单的方式来安排我从未考虑过的数据。如果是这样,请随时加入。

谢谢!

Sub CopyingCodesCALG()
    Dim Standard As Date
    Dim i As Integer
    Dim lastrow As Long

    lastrow = ActiveSheet.Cells(Rows.count, "B").End(xlUp).Row
    Standard = Date - 3
    StandardW = Date - 2
    Date1 = Date - 1
    'this utilizes Activesheets, may have to find a workaround for this depending on the data. Maybe add it to the MF and use thisworkbook?

    Rows("1:1").Select
    Selection.AutoFilter
    ActiveSheet.UsedRange.AutoFilter Field:=3, Criteria1:= _
        "Livraison"
    ActiveSheet.UsedRange.AutoFilter Field:=11, Operator:= _
        xlFilterValues, Criteria2:=Array(2, Standard, 2, StandardW)
    ActiveSheet.UsedRange.AutoFilter Field:=25, Criteria1:= _
        "=Return to warehouse", Operator:=xlOr, Criteria2:="="
    ActiveSheet.UsedRange.AutoFilter Field:=17, Criteria1:=Array( _
        "Data received", "Data received - shipment not received", "Loaded", "Loading", _
        "Optimized", "Received", "="), Operator:=xlFilterValues
    ActiveSheet.UsedRange.AutoFilter Field:=34, Criteria1:="="
    ActiveSheet.UsedRange.AutoFilter Field:=2, Criteria1:= _
        "INTLCM-CALG"

    i = 2

    For i = 2 To lastrow
        If Sheet1.Cells(i, 11) = StandardW And Sheet1.Cells(i, 32) > Date1 Then
            Rows("i:i").Select
            Selection.EntireRow.Hidden = True
        End If
    Next i

    ActiveSheet.AutoFilter.Range.Offset(1).SpecialCells(xlCellTypeVisible).Cells(1, 1).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
End Sub

0 个答案:

没有答案