Forum Discussion

Sue's avatar
Sue
Copper Contributor
Jul 16, 2021

Finding a date on another sheet.

Hi nice people, In my application I compute a variable called EntryDate (of data type date) from a form with DateSerial(txtYear,txtMonth,txtDay). This (using an example) produces 01/04/2021, which i...
  • HansVogelaar's avatar
    Jul 16, 2021

    Sue 

    This is a known problem. Excel VBA is very finicky when it comes to finding a date in a range.

    Two workarounds:

     

    1) If the dates in WorkRange are constants, not the result of formulas, change xlValues to xlFormulas:

    Set MyEdit = .Find(EntryDate, , xlFormulas, xlWhole, xlByColumns, , True)

     

    - or -

     

    2) Leave xlValues alone, and specify the first argument formatted exactly as on the worksheet:

    Set MyEdit = .Find(Format(EntryDate, "dd-mm-yyyy"), , xlValues, xlWhole, xlByColumns, , True)

    or

    Set MyEdit = .Find(Format(EntryDate, "mm-dd-yyyy"), , xlValues, xlWhole, xlByColumns, , True)

    depending on which format the cells use.

Share

Resources