运行时错误91

时间:2015-02-16 22:00:03

标签: loops excel-vba vba excel

我在Runtime 91 error行收到错误r = Bcell.Row。如何修复错误?

尝试定义范围以执行一些检查。

Dim LastRow, SECTYPE, Bcell, r As Range

LastRow = ActiveSheet.Range("D65536").End(xlUp).Row()

Rows("1:1").Select
Selection.AutoFilter
ActiveSheet.Range("A1:L" & LastRow).AutoFilter Field:=10, Criteria1:="X"

If LastRow > 1 Then
    Set SECTYPE = ActiveSheet.Range("D2:D" & LastRow)
    For Each Bcell In SECTYPE
        r = Bcell.Row


        If Trim(Bcell.Value) = "CO" Or Trim(Bcell.Value) = "PO" Then
            If (Trim(Bcell.Offset(0, -1).Value) = "SWAPOPT") And UCase(Trim(ActiveSheet.Range("i" & r).Value)) = "X" Or UCase(Trim(ActiveSheet.Range("i" & r).Value)) = "" Then
                    ActiveSheet.Range("J" & r).Value = "-"
                    ActiveSheet.Range("J" & r).Interior.ColorIndex = xlNone
        End If

        ElseIf Trim(Bcell.Value) = "FU" Then
            If (Trim(Bcell.Offset(0, 1).Value) = 1 And InStr(Trim(Bcell.Offset(0, -2).Value), "IB") <> 0) Then
                ActiveSheet.Range("J" & r).Value = "-"
                ActiveSheet.Range("J" & r).Interior.ColorIndex = xlNone
           End If


        ElseIf Trim(Bcell.Value) = "OS" Then
            If (Trim(Bcell.Offset(0, 2).Value) <> "AUD") Then
                    ActiveSheet.Range("J" & r).Value = "-"
                    ActiveSheet.Range("J" & r).Interior.ColorIndex = xlNone
            End If

        End If
    Next Bcell
End If

1 个答案:

答案 0 :(得分:0)

您需要Set这样的变量:

Set r = Bcell.Row