+ Reply to Thread
Results 1 to 6 of 6

Comparing dates does not work

  1. #1
    Registered User
    Join Date
    05-25-2017
    Location
    Buchs, Switzlerand
    MS-Off Ver
    2019
    Posts
    75

    Comparing dates does not work

    Hello,

    In a code, I compare the dates of a master File with those of a target file to determine where the last entry has been made. The code reliably conducts the comparison of Cell B37 of the target file with cell A12 of the master cell. For some reason, however, the code does not recognize when the dates are the same.

    The relevant part of the VBA:
    In the target file, "Date_new" gives me the last entry (January 6, 2023), which in this case is in cell B37:

    DATE_new = ActiveCell.Value

    Switching over to the master file...

    Windows("Current_Market_Data_Europe_extract_comparing dates_Master.xlsm").Activate

    That date is to be found in a table:
    If Cells(i, 1).Value = DATE_new And Cells(i + 1, 1).Value <> "" Then

    N.B. A "For...Next" loop relaibly leads to a value where cells(12,1).Value is addressed, i.e. the cell in the master file containing the entry "Jan. 6, 2023".
    Problem: The comparison doesn't work, despite the dates being the same (January 6, 2023), including the formatting. Even when I make a direct comparion in Excel (see Master file cell G25), the statement that they are equal gives me a "false". Why are the two dates with the same formatting regarded as not being the same?

    Excel_Arate

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,256

    Re: Comparing dates does not work

    Dates in Column A are TEXT which you are comparing (G25) against an Excel (numeric) date

    06.01.2023 vs 44932

    Hence FALSE

    This will return TRUE

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,483

    Re: Comparing dates does not work

    The formats are not the same, one is text and the other is a date value.

    You have a formula where you are spliting two dates in a cell.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Instead of trying to manipulate the dates in other sheets, you can remove the double dates in DAX_MW sheet.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    05-25-2017
    Location
    Buchs, Switzlerand
    MS-Off Ver
    2019
    Posts
    75

    Re: Comparing dates does not work

    Hi John,

    Thank you very much, yes, that seems to be it (and sorry for the late reply)! I actually thought it might have something to do with the formatting and checked the seetings in Excel. Attached in the word file you will see two screenshots for the settings of the cell (please apologize the German, but the words should be self-explanatory). Now how come in both cases, I'm shown that it's a date (whne in one case it's a text)? That still confuses me...
    Excel_Arate
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    05-25-2017
    Location
    Buchs, Switzlerand
    MS-Off Ver
    2019
    Posts
    75

    Re: Comparing dates does not work

    Thanks Davesexcel, Yes, good now I know where the formatting as a text comes from, thank you for pointing that out. I did sense that the problem might have something to do with the formatting. However when I checked the cell settings, both indicate that its' da date (please see the two screenshots in the word file and please apologize the German, but the words should be self-explanatory). Do you know the reason for this?
    Attached Files Attached Files

  6. #6
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,483

    Re: Comparing dates does not work

    It doesn't matter if the cell is formatted as date, the cell is filled with text.

+ 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] Comparing due dates vs. completion dates, with more than 2 outcomes
    By excel party in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 07-12-2020, 12:21 AM
  2. [SOLVED] Formating custom dates and comparing dates with different formats
    By OmniBlue in forum Excel General
    Replies: 2
    Last Post: 01-09-2014, 10:08 AM
  3. Comparing Two Work Sheets
    By akbar in forum Excel General
    Replies: 1
    Last Post: 01-15-2013, 12:07 AM
  4. [SOLVED] comparing two work books
    By sqlindia in forum Excel General
    Replies: 4
    Last Post: 07-22-2012, 10:54 AM
  5. Replies: 5
    Last Post: 06-24-2010, 06:21 AM
  6. Comparing Dates does not work properly
    By JMP86 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-03-2009, 04:58 AM
  7. Replies: 0
    Last Post: 12-19-2005, 07:45 PM

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