+ Reply to Thread
Results 1 to 2 of 2

Conditionally format cell with date output from user-defined function if not equal to toda

  1. #1
    Registered User
    Join Date
    08-16-2022
    Location
    Miami, USA
    MS-Off Ver
    365
    Posts
    5

    Conditionally format cell with date output from user-defined function if not equal to toda

    I'm trying to apply a CF rule that highlights a single cell with red fill if the date in the cell is not equal to today. Note that the cell in question calls a User-defined function. This function references the last save date of another excel workbook and displays the referenced date as mm/dd/yyyy.

    When I tried doing this the most straightforward way, using the conditional formatting option from home tab >Highlight cells rules>A date occurring... I found that I could format the cell to highlight green if it is equal to today, but not the opposite condition; because 'dates occurring' pre-defined CF rule only evaluates if the date is the same as a relative date from a limited list of options such as 'Yesterday' 'Tomorrow' 'Today'.

    Even if I programmed as many cell rules to highlight the cell in red for all the relative dates from this pre-defined list, it would only highlight in red certain dates that the cell's result is not equal to. I need it to highlight in red all dates not equal to today.

    I've tried programming the CF rule based on formulas, or based on the rule Format only cells that contain>Cell value>not equal to>=TODAY(), but when I do this, the rule always evaluates to true and always highlights the cell in red even if the date is equal to today. I deduce this is because the CF rule is not evaluating the date resulting from the UDF formula in the cell, but rather the actual formula, which is not equal to a date.

    Any help?
    Here is a redacted version of the code for my UDF function, if it helps.

    Please Login or Register  to view this content.
    I have `Optional VolatileParameter As Variant` in the parameter definition so that I can call NOW() when I call the function and make it volatile so that it autoupdates constantly and importantly as soon as the workbook is opened.

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Conditionally format cell with date output from user-defined function if not equal to

    FileDateTime() will return the date AND time of the last save of the file. Perhaps you want to return just the date? In which case, you'd need:

    Please Login or Register  to view this content.
    Then, let's say your date is in A1. Select A1 and add a new conditional format based on a formula of:

    Please Login or Register  to view this content.
    Choose to highlight in red when the formula is true.

    That should be enough.

    WBD
    Office 365 on Windows 11, looking for 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] Need VBA for System Generated Data to get Output in User defined format
    By KRIXXXX in forum Excel Programming / VBA / Macros
    Replies: 51
    Last Post: 04-30-2020, 05:15 AM
  2. Replies: 1
    Last Post: 01-04-2017, 06:00 PM
  3. Replies: 1
    Last Post: 01-04-2017, 05:59 PM
  4. Output Boolean Array from User-Defined Function
    By jben86 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-24-2013, 04:25 PM
  5. User defined function to output multiple values
    By firefly2k8 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-20-2010, 12:03 PM
  6. [SOLVED] Returning formatted output from a User defined function
    By Salman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-14-2006, 03:05 AM
  7. [SOLVED] How to output an array in Excel with a user-defined function?
    By Andy Chan in forum Excel General
    Replies: 2
    Last Post: 12-30-2005, 04:10 PM

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