Excel错误1004'找不到细胞'

时间:2016-03-08 16:22:36

标签: excel vba error-handling

所以,这会引发错误1004,没有找到细胞,他们处理错误的方式似乎不起作用。无论如何我能避免这个错误吗?谢谢!

${netty.version}

1 个答案:

答案 0 :(得分:0)

我发现这样的事情更容易理解:

Private Sub ComboBox1_Enter()

    Dim rrange As Range
    Dim VisibleRange As Range
    Dim rcell As Object

    Set rrange = Sheets("Project details").Range("A2:A150")

    Dim byCSMCoprId As String 'corp id goes into criteria for autofilter.
    byCSMCoprId = TextBox1.Text

    With Sheets("Project details").Range("A1:M1")
        .autofilter field:=2, Criteria1:=byCSMCoprId
        .autofilter field:=7, Criteria1:=""
    End With

    On Error Resume Next
    Set VisibleRange = rrange.SpecialCells(xlCellTypeVisible)
    On Error Goto 0

    If Not VisibleRange Is Nothing Then
        For Each rcell In VisibleRange
            ComboBox1.AddItem rcell
        Next
    Else
        Msgbox "No cells found"
    End if
End Sub