+ Reply to Thread
Results 1 to 3 of 3

Using DATEVALUE() Excel Formula within VBA when adding Custom Data Validation

  1. #1
    Registered User
    Join Date
    07-04-2012
    Location
    Derby, England
    MS-Off Ver
    Excel 2013
    Posts
    34

    Using DATEVALUE() Excel Formula within VBA when adding Custom Data Validation

    Hello, I wonder if it could be possible for someone to help me with an error I am receiving on the following part of my code, as I am trying to add some data validation to a range of cells through VBA that prevents users from entering a date that is not between 2 dates, and also weekends:

    Please Login or Register  to view this content.
    The error received is "Run-time error ' 1004':Application-defined or object-defined error" and when I "debug" the ".AddType" section above is highlighted yellow.
    If I remove the 2 "DATEVALUE()" parts of the "AND" formula the code works fine. Ultimately, I would like to be able to add my "StartDate" and "EndDate" variables within the "DATEVALUE()" parts of the "AND" formula.

    Please can someone help . . . Thanks in advance.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Using DATEVALUE() Excel Formula within VBA when adding Custom Data Validation

    Hi,

    Why reinvent the wheel. Why not use a custom data validation which is what it's designed for. e.g. in C1

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Where A1 & A2 are the two dates between which you will allow an entry.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    09-17-2014
    Location
    UK
    MS-Off Ver
    2007
    Posts
    117

    Re: Using DATEVALUE() Excel Formula within VBA when adding Custom Data Validation

    I don't think you can structure it like that as you are trying to contain everything within one formula.

    For selecting between values, you need formula1 for the start value and formula2 for end value:

    Please Login or Register  to view this content.
    This approach should work - just build your validation with the formula1, formula2 etc syntax. I believe this should work but haven't tried it with your example.

+ 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. data validation with custom formula
    By ashveena in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 05-15-2015, 03:29 PM
  2. [SOLVED] Formula for custom data validation
    By Butcher1 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-07-2015, 04:53 PM
  3. [SOLVED] Data Validation Custom Formula
    By dmartinet in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-11-2014, 03:33 PM
  4. Data Validation - Custom Formula
    By cyee in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 06-03-2014, 04:52 AM
  5. Data Validation - Custom Formula
    By Brandy in forum Excel General
    Replies: 5
    Last Post: 10-05-2009, 04:32 PM
  6. Data Validation Custom with Formula
    By bacalhoun in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-28-2007, 03:38 PM
  7. [SOLVED] Data Validation - Custom - Formula
    By DYeomans in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-02-2005, 01:06 AM

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