+ Reply to Thread
Results 1 to 6 of 6

Using Find Method to match dates

Hybrid View

Astroboy142 Using Find Method to match... 12-02-2009, 10:22 AM
pike Re: Using Find Method to... 12-02-2009, 06:52 PM
pike Re: Using Find Method to... 12-02-2009, 08:17 PM
Astroboy142 Re: Using Find Method to... 12-05-2009, 01:44 PM
pike Re: Using Find Method to... 12-05-2009, 04:58 PM
royUK Re: Using Find Method to... 12-06-2009, 05:17 AM
  1. #1
    Registered User
    Join Date
    09-26-2009
    Location
    Mississauga, Ontario (Canada)
    MS-Off Ver
    Excel 2003
    Posts
    49

    Using Find Method to match dates

    I am trying to use the .Find method to match a date. In sheet2 I have a range of cells which are formatted to only show the day "dd" (I could format each cell to show (dd-mmm-yy, etc). In sheet1, I have dates which are formatted as "January 7, 2009"

    I want to create a VBA find routine which allows me to match the date from Sheet2 (Ranged between cells A1:Z1) with Sheet1. Then output a MsgBox stating "Match found in cell $A$7 of Sheet1"

    I have tried a formula similar to:

    PHP Code: 
    Set FoundCell Sheets("Sheet1").Range("A1:Z1").Find _
       
    (what:=DateValue("January 7, 2009") ,lookin:=xlFormulas
    Any suggestions?
    Last edited by Astroboy142; 12-05-2009 at 02:06 PM.

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Using Find Method to match dates

    Hi Astroboy142
    try...
    Sub ptest()
    searchstring = "January 7, 2009" 
    Set LookInR = Sheets("Sheet1").Range("A1:Z1")
    With LookInR
               Set FoundOne = .Find(What:=searchstring, lookat:=xlPart)
            If Not FoundOne Is Nothing Then
                fAddress = FoundOne.Address
                Do
                   msgbow "Match found; " & fAddress
                  Loop While FoundOne.Address <> fAddress
            End If
    End With
    End Sub
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Using Find Method to match dates

    Dude how many dupilcate post do you have?

  4. #4
    Registered User
    Join Date
    09-26-2009
    Location
    Mississauga, Ontario (Canada)
    MS-Off Ver
    Excel 2003
    Posts
    49

    Re: Using Find Method to match dates

    personally, I don't think I have any double post

  5. #5
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Using Find Method to match dates

    Ok , dont know what I was think
    thanks for marking the post solved
    It refeshing to someone having a real go at the code before asking questions
    looks like your project is developing nicely

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Using Find Method to match dates

    A date in Excel is ctully a number (Long). When using .Find with dates you may get a problem searching for the date as a string. Try using

    Option Explicit
    
    Sub ptest()
        searchstring = "January 7, 2009"
        Set LookInR = Sheets("Sheet1").Range("A1:Z1")
        With LookInR
            Set FoundOne = .Find(What:=DateValue(searchstring), lookat:=xlPart)
            If Not FoundOne Is Nothing Then
                fAddress = FoundOne.Address
                Do
                    msgbow "Match found; " & fAddress
                Loop While FoundOne.Address <> fAddress
            End If
        End With
    End Sub
    If looking for multiple dates it might be faster using AutoFilter
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1