+ Reply to Thread
Results 1 to 2 of 2

VBA syntax to add formula in Data Validation Error alert

  1. #1
    Registered User
    Join Date
    07-09-2014
    Location
    Boston, MA
    MS-Off Ver
    2010
    Posts
    10

    VBA syntax to add formula in Data Validation Error alert

    Hi,

    Part of one of my macros puts data validation in a range of my cells. The validation is dates between 1/1/2013 and date(year(now()),12,31. I am wondering how to express the formula in the error alert. Here's what I have so far for my code, with where I need help highlighted in red:


    Range("A6:B10000").Select
    With Selection.Validation
    .Delete
    .Add Type:=xlValidateDate, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:="1/1/2013", Formula2:="=date(year(now()),12,31)"
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = "Invalid Date"
    .InputMessage = ""
    .ErrorMessage = "You have entered an invalid date. Please enter a date between 1/1/2013 and date(year(now(),12,31)."
    .ShowInput = True
    .ShowError = True
    End With


    Thanks all for your help.

  2. #2
    Registered User
    Join Date
    07-09-2014
    Location
    Boston, MA
    MS-Off Ver
    2010
    Posts
    10

    Re: VBA syntax to add formula in Data Validation Error alert

    Just an update, as I've been working to try and figure out a solution while waiting for replies:

    Formula2 = Sheets("Formula Sheet").Range("A2").Value

    In cell A2 on "Formula Sheet" i have the formula =date(year(now())+1,12,31)

    Range("A6:B10000").Select
    With Selection.Validation
    .Delete
    .Add Type:=xlValidateDate, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:="1/1/2013", Formula2:="=date(year(now())+1,12,31)"
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = "Invalid Date"
    .InputMessage = ""
    .ErrorMessage = "You have entered an invalid date. Please enter a date between 1/1/2013 and " & Formula2 & "."
    .ShowInput = True
    .ShowError = True
    End With



    I would like to build the formula into the VBA macro rather than have it refer to cell A2 on a worksheet, but I don't know the syntax of how to express that in the errormessage field.

    Anyone have any insights?

+ 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 Alert with Formula
    By jlo33 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-29-2013, 05:29 PM
  2. Data Validation Alert with Formula
    By jlo33 in forum Excel General
    Replies: 1
    Last Post: 10-29-2013, 01:05 PM
  3. Data Validation issue - alert when cell is blank
    By pbody in forum Excel General
    Replies: 1
    Last Post: 01-17-2013, 08:39 PM
  4. Data validation / warning alert
    By Chemistification in forum Excel General
    Replies: 4
    Last Post: 09-01-2010, 11:57 AM
  5. Data Validation Information Alert
    By RunHard in forum Excel General
    Replies: 2
    Last Post: 07-01-2009, 09:56 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