+ Reply to Thread
Results 1 to 10 of 10

Cells.Find xlDate does not find first date in sheet unless date format is dd/mm/yyyy

  1. #1
    Registered User
    Join Date
    11-06-2013
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2010
    Posts
    4

    Cells.Find xlDate does not find first date in sheet unless date format is dd/mm/yyyy

    Hello,

    I have an excel spread sheet that contains the following data:
    B1 = "01/10/2013"
    C1 = "02/10/2013"
    D1 = "03/10/2013"

    Cells are formatted with a custom format: dd-mmm-yy

    Please Login or Register  to view this content.
    loc.Address is returned as $C$1 but if I change the cell formatting to short date then loc.Address correctly returns $B$1.

    Is there anyway to find the first cell with a date in without changing the cell formatting? I am using .Find as the spreadsheet date location may change and eventually I want to open a worksheet (from another workbook), iterate through the date cells pulling the data in and the close it again. I don't control formatting of the worksheet to be read in and therefore would prefer not to have to open the worksheet and change the date format first.

    Cheers,

    Tom

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Cells.Find xlDate does not find first date in sheet unless date format is dd/mm/yyyy

    Hi Tom

    This seems to work:

    Please Login or Register  to view this content.

    Copes with short date, long date, and your custom date format.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    11-06-2013
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Cells.Find xlDate does not find first date in sheet unless date format is dd/mm/yyyy

    TMS,

    Thanks for the quick response. xlFormulas does work, but alas the dates, for some reason, are actually formulas with D1 (in this example) an actual date and C1 "=D1-1" and B1 "=C1-1".

    Any other suggestions? I can do workarounds if required but just wanted to check I wasn't missing something.

    Cheers,

    Tom

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Cells.Find xlDate does not find first date in sheet unless date format is dd/mm/yyyy

    Sorry, using Find with xlDate is not something I'm familiar with ... but it was a problem I was interested in following up. I tried xlWhole instead of xlPart but that didn't work. So I tried xlFormulas instead of xlValues and that seemed to consistently find the right cell.

    I don't understand the foibles of this function well enough to offer any other suggestions.

    I have asked if anyone else can provide any advice:

    http://www.excelforum.com/the-water-...ml#post3467030


    Regards, TMS

  5. #5
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Cells.Find xlDate does not find first date in sheet unless date format is dd/mm/yyyy

    May be check your Date Setting in Regional Date & Time Setting in Control Panel and confirm.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Cells.Find xlDate does not find first date in sheet unless date format is dd/mm/yyyy

    What do you think xlDate is doing in the find function?

    xlDate = 2

    So with dd/mmm/yy format the 2 in 02/Oct/13 is found.
    with Short date (dd/mm/yyyyy) the 2 in 01/10/2013 is found.

    Maybe you can use the FindFormat

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Cells.Find xlDate does not find first date in sheet unless date format is dd/mm/yyyy

    @Andy:

    I get
    Run-time error '1004':
    Application-defined or object-defined error
    on the
    Please Login or Register  to view this content.
    line


    Regards, TMS

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Cells.Find xlDate does not find first date in sheet unless date format is dd/mm/yyyy

    Looks like the Numberformat is fussy.

    these work
    [/code]
    Application.FindFormat.NumberFormat = "dd/mm/yy"
    Application.FindFormat.NumberFormat = "d-mmm-yy"
    [/code]

    this does not
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    11-06-2013
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Cells.Find xlDate does not find first date in sheet unless date format is dd/mm/yyyy

    Brilliant - Application.FindFormat.NumberFormat = "d-mmm-yy" works exactly right. Thanks a lot.

    I should have realised that xlDate was being resolved into it's numerical constant of 2 and therefore that is what it was searching for. Reading the Excel Developer reference it said:
    What: Required, Variant - The data to search for. Can be a string or any Microsoft Excel data type.
    Obviously it means it can search for specific numbers, dates, etc. as well as strings but given the wording I thought xlDate might work just to search for any date. When it started to return results, albeit confusing ones, I thought it might actually work that way.

    Anyway - all sorted - thanks again, and TMS thanks for not giving up.

    Cheers,

    Tom

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Cells.Find xlDate does not find first date in sheet unless date format is dd/mm/yyyy

    You're welcome. Thanks for the rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Find the date and copy the values from the colum of the date find and paste to other sheet
    By nizzcmzph in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-20-2013, 10:03 AM
  2. Replies: 7
    Last Post: 11-18-2012, 02:28 PM
  3. [SOLVED] Imported data contains strings dd.mm.yyyy how can I convert to date format dd/mm/yyyy inVB
    By Boormo in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-05-2012, 05:48 PM
  4. find method fails to find custom format date
    By yot68 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-03-2012, 06:28 PM
  5. [SOLVED] opening excel file -> date format problem: DD/MM/YYYY vs MM/DD/YYYY
    By yung in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-18-2005, 09:06 AM

Tags for this Thread

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