.FindNext failing after a .Find function (excel vba)

前端 未结 2 559
旧时难觅i
旧时难觅i 2020-12-21 08:46

I am trying to use .Find and .FindNext to search through a single column of data. I first need to find the first cell containing the value \"Total\

2条回答
  •  太阳男子
    2020-12-21 09:21

    If "Total" isn't found, then FirstTotal will be Nothing, which will result in a Type Mismatch when you try to use FirstTotal for the "After" argument in the ResultRange Find (the 2nd line). This will prevent that error:

    Set FirstTotal = SearchRng.Find(What:="Total", After:=Cells(1, 1), SearchDirection:=xlNext)
    If Not FirstTotal is Nothing Then
       Set ResultRng = SearchRng.Find(What:="Tech", After:=FirstTotal, SearchDirection:=xlNext)
    End If
    

    Generally speaking any dependent Finds need to be treated this way.

    Clearly, some kind of Else statement is required here, but I don't know what that would be.

提交回复
热议问题