Results 1 to 2 of 2

Thread: Using Find Method of Rangeobject

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2003
    Posts
    12

    Using Find Method of Rangeobject

    I am having trouble with Find method recognizing a date formatted field below the varExistingRecord = "01/01/2002" - It doesn't work, but when I try and find a field that is entirely string data it works fine...Any tips or tricks? Excel '97 thanks.



    Private Sub UpdateExistingRecord()
    Dim varExistingRow As Variant

    With Worksheets(1).Range("a1:a6500")
    Set varExistingRow = .Find(varExistingRecord, LookIn:=xlFormulas)
    If Not varExistingRow Is Nothing Then
    MsgBox ("i found it" & varExistingRecord)
    Else
    MsgBox (" i didn't find!" & varExistingRecord)

    End If
    End With
    End Sub

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    That's because your search value is of a string data type and not a date data type. Try this:
    VB Code:
    1. Private Sub CommandButton1_Click()
    2.     Dim rngDateColCells As Range
    3.     Dim rngFirstMatch As Range
    4.    
    5.     Set rngDateColCells = Range("A1:A3")
    6.     Set rngFirstMatch = rngDateColCells.Find(CDate("02/01/2001"))
    7.    
    8.     If Not (rngFirstMatch Is Nothing) Then
    9.         MsgBox rngFirstMatch.Address
    10.     End If
    11. End Sub

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width