Error In Finding Date In Another Range

  • Hi Guys,


    This is really dumb of me but here goes...


    I have a formula =WORKDAY(TODAY(),-1) which will give me 10 Apr 07 in C1of sheet1 today.


    I am trying to find the cell in column A of sheet2 which has the date value equal to C1.


    However, my below macro keeps telling me object variable not set at the last line.. can someone enlighten me why?



    Cheers
    Lloyd

  • Re: Error In Finding Date In Another Range


  • Re: Error In Finding Date In Another Range


    tks theOkk,


    I tried.. but that cell which contains the exact same date is not being selected means it says theres no date found..... :confused:


    I realized if i change the cell format to number format means 10 Apr 07 = 39182 the macro will recognize.


    Is there a way for the macro to pickup this date format instead of the string/formula in C1?


    Lloyd

  • Re: Error In Finding Date In Another Range


    Quote from tardy


    Is there a way for the macro to pickup this date format instead of the string/formula in C1?


    Have you tried:

    Code
    Dim today As Date

    ?
    What exactly you want to find? TODAY()? Or WORKDAY?

  • Re: Error In Finding Date In Another Range


    Yup, i've tried that as well.. it still fails to find even though i changed the date format to match two cells exactly..


    Basically.. it only works when i change both to number format...

  • Re: Error In Finding Date In Another Range



    try this


    Code
    Dim s1 As Worksheet
        Dim s2 As Worksheet
        Dim tdy As Range
        Dim today
        Set s1 = Sheets(1)
        Set s2 = Sheets(1)
        today = s1.Range("C4").Value
        Set tdy = s2.Range("A:A").Find(WorksheetFunction.Text(today, "dd/mm/yy"), s2.Range("a:a").Cells(10, 1), LookIn:=xlValues, lookat:=xlWhole)
        Cells(tdy.Row - 1, 1).Select


    cheers!!
    senthil

  • Re: Error In Finding Date In Another Range


    Quote from tardy

    Is there a way for the macro to pickup this date format instead of the string/formula in C1?


    Something like that?:

  • Re: Error In Finding Date In Another Range


    HiHi theOkk


    Went out of office yesterday...


    ok that kinda works but i need to change the date format from 4-digit years (dd/mm/yyyy) to 2-digit years (dd/mm/yy) instead... Have you any idea how to do that?


    Or is there another method to specify the macro to look for the value of C1 in terms of serial value?


    Senthil : For your code.. I get an object required error message.. Also, why is it that you specified Cells(10,1)?


    :confused:


    Many thanks!!
    lloyd

  • Re: Error In Finding Date In Another Range



    Can you give us an example of your file?

  • Re: Error In Finding Date In Another Range


    Unlike some other languages, in this declaration,

    Quote from the Okk
    Code
    Dim s1, s2 As worksheet

    s1 is declared as a variant.

    [SIZE=1]Entia non sunt multiplicanda sine necessitate.[/SIZE]

  • Re: Error In Finding Date In Another Range


    Hi,


    Finding dates can be a real pain in excel sometimes.


    This code below is tested and works. However it is important that the date format in the code matches the date format in the search range on the worksheet.



    Good Luck.

  • Re: Error In Finding Date In Another Range


    it is really such a pain in the a**!!!!!


    I will try that out later reafidy... thanks a million! ;)



    shg: So it is advisable to seperate the two declarations?


    Regards,
    Lloyd

  • Re: Error In Finding Date In Another Range



    Yes you need:

    Code
    Dim s1 as worksheet, s2 as worksheet
  • Re: Error In Finding Date In Another Range


    There is only one date in the sheet, why dont you provide a proper example with lots of dates so we can see the formats there is nothing even in c1 which is the date you are searching for...

  • Re: Error In Finding Date In Another Range


    Thanks reafidy..


    I have also found one grunt way to circumvent this problem...


    Code
    Sheets("Sheet1").Range("A1").numberformat = "0"
    Sheets("Sheet2").Range("A:A").numberformat = "0"
    
    
    .............................. - i perform the search and other stuff here
    
    
    Sheets("Sheet1").Range("A1").numberformat = "DD MMM YY"
    Sheets("Sheet2").Range("A:A").numberformat = "DD MMM YY"


    This is after i Dim Today as Long and using serial number to search instead...


    Your code works perfecto.. !


    Really appreciate your help here... tks once again :music:

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!