Keep getting Error 91 with Excel Find function

前端 未结 1 623
有刺的猬
有刺的猬 2020-12-07 06:36

I\'ve tried the suggestions on this site and none seem to work.

In cells C6:Z6, I have dates 01/01/2011 through to 01/12/2012 (in UK date format). I run the followin

相关标签:
1条回答
  • When you simply search for "01/08/2012", you are actually searching for a string. You have to convert it to a date using CDate.

    Also it is better to check if anything is found using If Not aCell Is Nothing Then to avoid any errors. See my post in this link.

    Try this

    Sub FindDate()
        Dim aCell As Range
    
        Set aCell = Range("C6:Z6").Find(What:=CDate("01/08/2012"), After:=ActiveCell, _
        LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
        SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    
        If Not aCell Is Nothing Then
            MsgBox aCell.Column
        Else
            MsgBox "Not Found"
        End If
    End Sub
    
    0 讨论(0)
提交回复
热议问题