+ Reply to Thread
Results 1 to 4 of 4

Adding date validation with VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    11-12-2015
    Location
    England
    MS-Off Ver
    2016
    Posts
    26

    Adding date validation with VBA

    Hey

    Pretty basic, but I want a script to add a date validation to a cell so that the user can only enter in the format of xx/xx/xxxx

    I would also like the error to indicate this to the user as well

    Thanks in advance

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Adding date validation with VBA

    Here's a recording:

    Sub DV()
    '
    ' DV Macro
    '
    
    '
        With Selection.Validation
            .Delete
            .Add Type:=xlValidateCustom, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:="mm/dd/yyyy"
            .IgnoreBlank = True
            .InCellDropdown = True
            .InputTitle = ""
            .ErrorTitle = "ErrMess"
            .InputMessage = ""
            .ErrorMessage = "Must be xx/xx/xxxx"
            .ShowInput = True
            .ShowError = True
        End With
    End Sub
    Any more details, maybe we can edit this into something more useful.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    11-12-2015
    Location
    England
    MS-Off Ver
    2016
    Posts
    26

    Re: Adding date validation with VBA

    Got it, nice one!

    Thanks!

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Adding date validation with VBA

    You're welcome!

+ 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. Adding Data Validation
    By k64 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-14-2016, 06:03 PM
  2. Adding Date Data Validation to cells with List Data Validation
    By biggtyme in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-03-2013, 09:47 AM
  3. Date and count validation in single cell - Custom Validation
    By murugavelmsc in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-16-2013, 05:25 AM
  4. Adding data validation drop down with VBA
    By jammusi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-06-2010, 11:32 AM
  5. Adding Data Validation Values
    By Sandra808 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-03-2010, 02:29 PM
  6. Validation List -adding data and using it later
    By POC in forum Excel General
    Replies: 1
    Last Post: 07-23-2006, 12:45 AM
  7. Adding a validation list by code
    By Philippe Pons in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-01-2005, 12:05 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