+ Reply to Thread
Results 1 to 5 of 5

Macro to trigger Data Validation

  1. #1
    Registered User
    Join Date
    10-06-2009
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    23

    Macro to trigger Data Validation

    Hello Experts,

    Could you tell me how to trigger a Data Validation to be perform on a particular cell through VBA? This validation is not triggered if the cell value is changed via a macro.

    This is my exact situation if the above is not clear enough:

    I have a Calendar Form which allows user to click on a date and it inserts the date into a cell. This cell has a validation rule against it, which displays an error message if it does not satisfy certain conditions (what they are is not important). This works fine if the date is inserted by key. However, if the the value is inserted by the Calendar Form (through a macro), the cell gets populated bypassing the data validation rule of the cell. I understand that one can use code to check if the cell conform to the conditions in the first place before insertion, but I don't want to hard code the error message somewhere inside my VBA script. Is there a method to trigger the validation to run?

    Thanks guys in advance.
    Fan

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Macro to trigger Data Validation

    Just perform the same check in VBA and output a MsgBox if it fails.

  3. #3
    Registered User
    Join Date
    10-06-2009
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    23

    Re: Macro to trigger Data Validation

    Hi Bob, The thing is my macro can be used to insert a value to different cells (depends on which cell is selected when run) and they have different validation conditions. I want my script to be as general as possible and not hard-code any conditions and messages.

  4. #4
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Macro to trigger Data Validation

    Could you not extract the DV formula and evaluate that?

  5. #5
    Registered User
    Join Date
    10-06-2009
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    23

    Re: Macro to trigger Data Validation

    It sounds like this can work. Would you be able to tell me how I can extract the formula and display the message of the DV on a particular cell?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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