Comments on: Excel Data Validation: custom formulas and rules

In yesterday's tutorial we started to look at Excel Data Validation - what its purpose is, how it works, and how to use built-in rules to validate data in your worksheets. Today, we are going to take a step further and talk about the nitty-gritty aspects of custom data validation. Continue reading

Comments page 2. Total comments: 201

  1. I have a group of taxi's (each with its own unique number) that check-in and out throughout the day. They are recorded with the date, check-in time and check-out time. I don't want to allow the taxi to be able to check in if there is not a check out date from the previous visit, i.e., a blank check-out date. The validation would need to look at the empty cell of the previous visit, based on the taxi number in the table, and disallow entry if there is an incomplete date for the previous visit. Is this allowable since the validation would need to look for a blank cell?

    1. Hi! You can create a Data Validation for only one specific cell, not for a table column. You can use conditional formatting for the range B2:B1000 so that the cell is color-coded if no date in column B is specified for the previous visit. Here is an example of a conditional formatting formula:

      =AND(NOT(ISBLANK(A2)),ISBLANK(INDEX($B$1:B1,XMATCH(A2,$A$1:A1,0,-1))))

  2. H Alexander,

    I hope you had a great week so far.

    I need help with the following:

    I have some data containing different countries and I want to create a data validation+warning.
    So, I have Germany, UK and Spain and their codes are 1, 2 and 3. On the next column I wish to warn the user that they cannot input Germany(this is the main country,1) and they need to choose UK(2) or Spain(3).
    However, I wish to make it so that the warning specifies if it needs to be UK or Spain, like this: WARNING, please input UK. or WARNING, please input Spain
    So I don't want the warning to mention both countries, but the precise one.

    Much appreciated,
    George

    1. Hi! If I understand the question correctly, you want to modify the warning on data entry. With Data Validation, you cannot change by condition the warning when data is entered into a cell. You can do that with a VBA macro. I hope I answered your question.

      1. You did,

        Much appreciated,
        George

  3. I have several small ranges of cells (5 cells per range), where within each cell of each range uses a simple dropdown (blank, Yes). I would like to restrict the user to only being able to select "YES" for one of the cells within each range. They will be able to select "blank" for multiple cells, but the "Yes" can be selected for only one cell. Do you know of a conditional format formula or other tool to enforce this?

    Thanks,
    Matt

    1. Hi! You can use the Data Validation tool for a single cell only. For a range of cells, use the VBA macro.

  4. Hello,

    I want the column C to only accept English lower case letters, numbers, and the dash (hyphen).
    Thanks.

    1. Hello! The answer to your question can be found in this article: Excel Data Validation using regular expressions.
      You can use the following expression to resolve only lowercase letters, numbers, and dashes in Excel Regex:

      ^[a-z0-9-]+$

      This expression starts at the beginning of the string (^) and ends at the end of the string ($). Inside the square brackets are all the allowed characters: lowercase letters (a-z), numbers (0-9), and dashes (-). A plus sign (+) indicates that there must be one or more matches of allowed characters.

  5. In a range 8 cells I want to fill any 5 cells with data. If I try to enter the 6th data is should return an error message indicating already 5 cell entries done. No more data allowed in this range.

  6. Hello,

    Is it possible to create a specific drop down box for a specific value in another drop down box? I have a drop down box for each department and now want to have a specific drop down box for each departments functions for them to select. I appreciate any help you can provide.

    Thank you!

  7. For a single cell, i need to apply multiple data validations. First one is List (set of values) as a drop down. Second one is custom formula checking the length of the previous cell is not equal to zero. How can both be applied at the same time?

    1. Hi! Two data validations cannot be applied to a single cell. You can use a VBA macro for the second validation.

  8. Hello,

    Is it possible to create a custom data validation formula so that if data is entered into a row, a certain cell within that row MUST have data inputted?

  9. Hello. Can i ask if posible to make data validation on cell that allow only to input greater than number from the present number from the cell.and show error if i input less than the present number from the cell. In short the input number must be always greater than the present number.without using minimum number.thank you if somebody can help.

    1. Hi! A formula can't refer to the cell in which it is written. So your data validation can only be done with a VBA macro.

  10. Hi, is it possible to have a set of letter values (as in like a regular "List" data validation) + whole numbers only? without having to list down all numbers in the list used in data validation?

    E.g.
    List = A,B,C,D
    Cells should allow, A or B or C or D or any whole numbers but should not allow E or any other words.

    1. Hi!
      Specify all conditions using the OR operator. To define integers, use the INT function.
      Try this formula:

      =OR(A1="A",A1="B",A1="C",A1="D",IF(ISNUMBER(A1),A1=INT(A1)))

  11. Good morning, I hope you're doing well. My question is how do I use custom data validation to "only enter currency values without decimals" in a certain column?

    1. Hello! Compare the number you enter with the same number rounded to integers.
      For example, use this formula data validation for column C:

      =C1=INT(C1)

  12. I am looking for a validation rule to do this. The custom
    We are currently using Excel Shortcuts to enter the dates in the cell (Date & Time Shortcut = Ctrl+; then Spacebar Ctrl+Shift+;)
    The date is always displayed as 12 04 2023 12:19. I have even tried to write a macro to run when you save the file to change the Date Columns to the correct format, to no avail!!
    Will it be possible to do this with Data Validation??
    And how will I go about it? I understand after looking at your explanations it will need to be a Custom Validation, but I have no idea how to do it or where to begin.
    I have made an Input form on an Excel sheet to capture the data and transfer it to the correct worksheet. Al that is working.
    My challenge is the date/Time format on the input form.
    Regional Settings on PC
    Format - English (South Africa)
    Short Date - dd MMM yyyy
    Long Date - dd MMMM yyyy
    Short time - HH:mm
    Long Time - HH:mm

    Thanx

  13. How do i create data validation for range of cells where sum of all the cells in that range not to exceed a particular value

    1. Hello!
      Select a range of cells (e.g. A2:A10). Create a data validation rule for this range with the formula SUM (for example SUM(A2:A10)<20)
      I hope it’ll be helpful.

  14. I have a sheet with all the users assigned to a project. Now, this is a live sheet which needs to be updated periodically. Is there any way, I can add a restriction, so that an user can only edit their own data (perhaps using their own User ID as a key)?

    Thanks!

  15. I want to creat a custom date like mm-dd-yyyy is possible

  16. Good day

    How would I go about to allow only a-z or A-Z (no numeric in the text) and also that the entry may not exceed 40 characters. With ISTEXT it allows abc123. Thanking you in advance.

  17. Without wanting to push my luck (because I already had a question answered here in record time)... :-)

    Is it possible to automatically hide/unhide rows/columns depending on the answer in a validated list?

    Example:

    A1 contains a validated drop down list of nationalities (100+ options)

    In Row 2 I have written (field B1): ID number. But that entire line (where the answer has to be given in B2 what the ID number is) should only be visible if in A1 the Answer "Dutch" was selected.

    If any other value that "Dutch" was selected in A1, then row 2 should be invisble but row 3 (where the person has to fill in his Social Security number should become visible.

    So in short: if A1 = "Dutch" then make row 2 visible and row 3 invisble. If A1 = any other value than "Dutch" in the dropdown menu, then make row 2 invisble and row 3 visible.

    Thanks again!

  18. Hi,
    I need to find a solution to the following challenge

    Cell B2 has a dropdown list of 5 choices (A/B/C/D/E as an example)

    Cell C2 now needs to contain dropdown lists which are particular to what is in B2. So If B2 = "A" then the dropdown in C2 needs to contain a certain amount of options in a dropdown menu which is tied to "A" (these values that are linked to A/B/C/D/E are in a separate tab and are each in a different column in that tab sheet).

    I tried "custom" and then went for =if(B2="A"; [target fields for dropdown linked to A here]); if(B2="B"; [target fields for dropdown linked to A here]); ... and so on.

    But that does not work. :-(

    Many thanks!

      1. Hi Alexander,

        Yes, that's it! Many thanks!!! (also for the lightning-fast reply :-)

        Kind regards,
        Philip

  19. Hello,
    Is there a possibility to set up a different areas to search in based on data in a specific cell?
    Imagine you have ten customers. In one cell (B11), you use data validation - list - source (K10:K20) to choose the customer from the list.
    Any idea how to arrange that in another cell (B21) I could choose from the list of different sides that every customer has, but only from the list that belongs to the particular customer?
    Thank you,

  20. Using custom validation, the cell can only show "0" or values between 10,000 - 36,000. How do I do this?

  21. Is it possible to create a data validation formula that returns only the distinct values from a table column?

      1. Sorry Alexander, I did not qualify the challenge well. The end game is to have a cell with a drop-down data validation list. The content of the list contains only the distinct values contained in a column of a table. The table rows are dynamic based on the data query that populates the table.

  22. Sir, how I write a data validation formula for entering a text and number combination format of 320.6 ABC.
    It should always be 3 digits, 1 decimal, then space and 3 English characters. format should be 320.6 ABC

    Thanks

  23. Hey!

    This was awesome. If I want to have a drop down of the numbers 1-50 and they can only select each number once (for example, identifying a list of their top 50 out of 2000) what formula would I use?

  24. Hello,
    Could you tell me please how to set up a column where only a four digit number is allowed (a year)? Thank you.

  25. Hi, thank you for your valuable help. Could you please tell me how I can ensure that my user enters Text first then numbers? Examples: ABC123 or ABCD12 or AB1234 etc, there is no set rule to 'count' of alphabet or numbers.

  26. Hey! So I'm trying to do a nested if function for a list dropdown and my issue is that I have too many options and it exceeds the character limit of the source bar in the data validation popup. Is there any way to get around this?

  27. Hi,

    I have a drop down menu with a list of percentage ranges and I want a different calculation dependent on each selection:

    < 90% then deduct 10% from cell E9 and update total in cell L9

    90-95% then deduct 5% from cell E9 and update total In cell L9

    96-99% then deduct 2.5% from cell E9 and update total in cell L9

    I initially tried IF statements based on the ‘text’ selected but it is only updating the total based on each individual cell with a drop down list, and I need each cell with the drop down menu to keep updating one cell total collectively.

    Can you help at all please?

    1. Hi!
      If a value is written in cell E9, then you cannot change it using an Excel formula. We have talked about this many times in our blog. This can be done using a VBA macro. You can write an IF formula with nested conditions in another cell based on the selected text.

  28. HI,
    I have a data set with a validation rule which does not allow names to be duplicated across the row. I would like to add a drop down list for the names to be selected from but when I try to do this it erases the previous validation rule which prevents the duplication. Is there any way I can add these two rules together?
    Thanks

  29. Hi,

    I created a data validation drop down list.

    A: Date not synced
    B: Term
    C: Item
    D: Amount
    E: Combination: ________

    Like to ask your help on how to put a formula, when I pick "E" I can write a comment on the it. Like for example, combination of A&B or C&D or ABC or combination of everything

    1. Hi!
      You cannot change the values that are inserted into a cell using a drop-down list. You can create in your dropdown list more options for item e and write down all the possible combinations.

  30. I need to restrict a field using Data Validation so that the user can only enter a Proper Name which means it must be entered using uppercase letters, numbers and only the following 4 special characters
    ,(comma)
    -(dash)
    & (Ampersand sign)
    ' (Apostrophe)
    How would I do this? in a long statement specifying all the valid characters, or in a table that is 1 column with all the valid characters?

  31. Hi!! I'm really dumb at such things like this, I'm in my 1st yr of college and we need to do data validation. C2:C7 contains the salary ( which the criteria, the amount must be 12, 000-35,000 ), and the next cell D2:D7 contains the bonus salary. The bonus salary must be 12% of the salary or cannot be greater than 12%. I know I need to make a custom formula but I'm really dumb at logic and maths, please help. Thank you and I apologize for my dumbness, have a great day <3

    1. Hi!
      The formula returns TRUE if the bonus salary does not exceed 12% of the basic salary:

      =IF(D2/C2<0.12,TRUE,FALSE)

      or

      =D2/C2<0.12

      Please check out this article to learn how to create conditions with IF function in Excel.

  32. Hi,
    How to restrict any profile in validation rule formula, that means I don't need to run that user in validation rule.. So any formula

  33. Hi Alexander, thanks for your answer.

    I have done the regular drop-down list.
    Now, what I need is to be able to select data from the list in cell A1 and get it to show me "blue", whilst on cell B1, I select the same item on the same list but I get it to show me "1".
    Do you understand what I mean?

    Thanks for your help.

  34. Hi there,

    I have a cell with a data validation list dropdown. I want to make a rule to get the cell to show something different when a particular value of the list is selected. Is this possible?

    For example, let's say I have a list from 1 to 10. I want the list to show all the numbers normally, but I want the 1 to show "Improvement needed!" and the 10 to show "Awesome!", however, I need the list to still be 1 to 10, as I would need to do other operations with the data of that list.

    Thanks for your help.

    1. Hello!
      A regular drop-down list inserts the data it shows into the cell.
      An ActiveX ComboBox (Developer - Insert menu tab) may be suitable for your task.

  35. I want the cell to except only Capital M. How would I that?

    Thanks

    1. Hello!
      I hope you have studied the recommendations in the tutorial above. It contains answers to your question.
      Formula =A1="Capital M"

  36. Can I restrict the entry to one decimal point? The problem is even if I set the format of cell as number with one decimal point, when I enter 0.12, the value is still stored as 0.12 despite the number show in the cell is 0.1.

      1. thanks a lot

  37. Hi
    Using data validation, I know it is possible to do the below separately:

    1. Create a data validation drop down list (ALT + A + V + V then select list from the 'Allow' field and denote the cell range in the 'Source' field)
    2. Prevent users from entering data into one cell (e.g. cell A2) if another cell (e.g. cell A1) has not yet been populated (ALT + A + V + V then select Custom from the 'Allow' field and insert '=NOT(ISBLANK(A1))' in the 'Formula' field)

    However, I am in need of a combination of both. I need to customise a cell such that if cell A1 is not populated, then cell A2 cannot be populated but, when cell A1 has data inserted, A2 should be able to be populated but only through a drop-down list. May you assist

    1. Using data validation, I know it is possible to do the below separately:
      ...
      2. Prevent users from entering data into one cell (e.g. cell A2) if another cell (e.g. cell A1) has not yet been populated (ALT + A + V + V then select Custom from the 'Allow' field and insert '=NOT(ISBLANK(A1))' in the 'Formula' field)
      ...

      How do you know that?? It's NOT working!

      ...Does anyone know if it's possible to use as a condition in formula of Data Validation empty cells??

      1. Hello!
        Use the following formula for data validation

        =NOT(ISBLANK(A1))

        Uncheck "Ignore blank". It works.

  38. First row of my spreadsheet is the column titles.
    In row 2 I have four Data Validation drop downs, each column drop down is dependent upon whichever item is picked in the drop down in a previous cell in the same row, but not necessarily adjacent columns. All is working correctly in row 2
    The spreadsheet has 500 data entry rows to allow recording of approx. 6 to 10 jobs per day. How do I extend the Data Validation List rules to all 500 rows?
    I have used Copy/Paste Special/Validation on each column but this is not working correctly. Is the copy/paste method I am using the wrong one for this application?

    1. Above issue resolved. Was a syntax error in one of the formulae where $C$4 was locking drop-down lists to a single cell.

  39. Hi,

    We have a spreadsheet that currently monitors the jobs our contractors are at, and the total hours worked overall for the week. We have the list of employees on the one sheet, and we use the Data Validation drop down to select the jobs for the hours, and I was wondering if there is a formula to also calculate the number of hours based on each specific job, as well as the overall total hours I have listed.

    Thanks.

  40. I want to know formula to list down the data validation list when x collum value is Yes else it shoud show not applicable. please help

    1. Hello!
      Explain what the phrase "list when x collum value is Yes" means? Is each cell in the column "Yes"?
      Please describe your problem in more detail. Include an example of the source data and the result you want to get. It’ll help me understand your request better and find a solution for you.

  41. Hi, I have a requirement to allow multiple set of numbers in a cell, for example, (00001, 02334, 01289), retaining leading 0s and limit to 5 digits each number, how can I write a formula for this? can someone help me, thanks

    1. Hello!

      If I understand your task correctly,
      Set the cell to "Text" format and use Data Validation - Allow - Text length

      If you want to use numbers, set the custom format "00000" in the cell and use the Data Validation formula
      =A1<1000000

      I hope it’ll be helpful.

      1. Hi, thanks for getting back on this, the formula and the steps mentioned works for one set of number given on that cell, for example, 00012. My requirement was to enter multiple set of numbers, for example (00012, 11111, 12359, 88888, etc...) which does not work.

        1. Hello!
          I wrote this formula based on the description you provided in your original comment. Please note that if you’d provided me with the precise and detailed description of your task from the very beginning, I’d have created a different formula that would have worked for your case. However, even now your question is not precise enough. 00012, 11111, 12359, 88888 written as text in one cell? If so, why are you talking about numbers and leading 0s?

  42. Why might a logically TRUE formula trigger a FALSE in Custom Validation.
    =AND(COUNTIF(Root_Rank,O6)0,O6<=3) is TRUE when O6 is 1, 2, or 3 but fails validation.

    1. Sorry formula truncated. =AND(COUNTIF(Root_Rank,O60, O6<=3)

  43. Hi team,
    For some reason this validation rule is not triggering the stop alert in cell E9 when I enetr "X". $R$6=3 and I have entered "X" in three other worksheets in cell "E9". I wonder if you can help-
    =SUMPRODUCT(COUNTIF(INDIRECT('Sheet names'!$E$2:$E$7&"!"&CELL("address",E9)),"*"&"X"&"*"))>$R$6

    1. I figured it out. Just realized that the alert is triggered by "False" argument, not "true" argument. I just had to change the formula to "".

  44. Hi,
    I'm having difficulty with a custom Data Validation formula. I want it to check two nearby cells for existing values of 1; both these cells must not contain 1 (so if either does contain 1, the validation fails).
    I've tried creating a macro but no matter what it does, it always fails to validate. I then tried entering a formula which works when tested in the sheet, but it always fails to validate when entered as a formula in Data Validation. Any clues please?
    =AND(INDIRECT(ADDRESS(ROW(),COLUMN()+1,4))1,INDIRECT(ADDRESS(ROW(),COLUMN()+3,4))1)

    1. Obviously the system here doesn't like my greater-than/lesser-than symbols as it's stripped them out of my formula!! Here it is again but without using those symbols:-

      =AND(INDIRECT(ADDRESS(ROW(),COLUMN()+1,4))not equal to 1,INDIRECT(ADDRESS(ROW(),COLUMN()+3,4))not equal to 1)

      1. Hello Teresa!
        In the conditional formatting and data validation formula, the INDIRECT function does not work with the logical functions IF, AND, OR, and others. Therefore, I recommend that you divide your formula into 2 parts and create 2 conditions.

        =INDIRECT(ADDRESS(ROW(),COLUMN()-1,4))<>1

        and

        =INDIRECT(ADDRESS(ROW(),COLUMN()+1,4))<>1

        I hope this will help

  45. How do i lock a validation rule but can enter data in the cell

    1. Hello!
      It is not possible to block a data validation rule. It can only be deleted. More sophisticated data validation methods are possible using the VBA macro.

  46. Hello Ablebits team,
    I'm having a hard time to figure out how to make options of a drop-down list, containing formulas, working with relative reference when I paste special with validation in another cell, without using VBA if possible.
    For example, when I copy validation from cell P31, including a list option with the formula "=MIN($D31;$K31+L31)" and paste it to cell P33, I need this formula to change automatically into "=MIN($D33;$K33+L33)".
    Could that be possible in anyway? Thank you in advance!

    1. Hello Yannis!
      When you copy cells, data validation formulas change in the same way as regular formulas. You can check it yourself.

      1. Hello Alexander and thank you for your quick response,
        I've tried it before and it seems not to be working, since the result I get by selecting this list component, is the same for every cell I paste the validation into.
        Let me clarify that it's a list containing the formula (including the value zero and the formula) and not a custom validation, where I could write the formula directly into the box while creating it, in case this detail is of any importance.
        Is there any worksheet setting I should turn on or off?

        1. Yannis,
          Thank you for the clarification. I mush have misunderstood your previous comment. I supposed you're using a custom validation formula applied to some data range and this formula is the one that doesn't get updated. If however, it is the range with different formulas you've set as the data validation source range, those formulas won't be recalculated when copying. You see, Excel uses not the formula but the end result for the validation, no matter where this validation list is.
          I hope this will help, otherwise please do not hesitate to contact me anytime.

  47. Column B Defines the scope of the product with two variables Yes or No e.g. Cell B1 = Yes/No
    Column C - Cell C1 has data validation of three parameters Simple/Medium/Complex.
    If the value of Cell B1 is Yes for the Scope; then only Cell C1 should get activated and the user should be able to choose the type of the parameter by clicking the drop-down arrow i.e. Simple/Medium/Complex.
    Please advise the formula or procedure to do the same.
    Best Regards

  48. Dear All I am from India, please help me I got fade of to make this 'custom data validation isuue solved. I made a table having multiple column.
    Column 'C' contains 'Items in innitial Stock', 'D' contains 'No. Of Used items', and 'E'containes 'Faulty items'.

    Now three isuue are that (1) 'E' cant be greater than either the 'C'or 'C-D' and (2) if Stock 'C' is empty/blank no Entry should be allowed in 'E'.
    And (3) if C is having 20 items and no item is used (it means 'D' is balnk), but some items foud faulty, so 'E' must not be greater than 'C'. And it must generate erro message if these condition violated.
    I tried more than 50 Formula but it satisfied only 2 conditions.
    plase help to make this formula.

    1. Hello Santosh,
      Please try the following formula for data validation for cell E3:

      =IF(AND((C3-D3)>=E3,C3>0,C3>=E3), TRUE, FALSE)

      You can learn more about Data Validation in Excel in this article on our blog:
      https://www.ablebits.com/office-addins-blog/data-validation-excel/#custom-data-validation-rules
      https://www.ablebits.com/office-addins-blog/excel-data-validation-custom-formula/

      Hope you’ll find this information helpful.

  49. I'm trying to set up a validation rule to connect the value in one column to an appropriate valid value list in another column. For example, I have a validated cell (let's say B2) where the value is validate via a list on Sheet 2 in cells A1-A3. THe valid values in the list include three names: Paul (A1), Peter (A2) and Pamela (A3). Now, on sheet 2 I have a list of Paul's prefered toys in Cells C1-C10, Peter's list is in D1-D10 and Pamela's are in E1-E10. Now, back on Sheet 1 I want to create a validation formula in Cell B3 that says...... Refer to cell B2, if the value in the cell is the value in Sheet 2, Cell A1 then select from the list in Sheet 2, between cells C1-C10. If it's A2, then select from the list in sheet 2 cells D1-D10, and so forth. Is this possible? Another way to look at this is, I want to limit choice number 2 based on choice number 1. If I'm making a selection for Pauls' Christmas present, I only want to see the things on Pauls' Christmas list. Thanks for any help you can provide.

  50. I have 3 drop-downs (one in column A, B & C). Column A will have names, Column B will have catalog names and Column C will have item codes). I want to show multiple values in Column C based on what was selected in Columns A & B. So if I kept the name the same from column A but changed the category in Column B, then Column C will return different values based on the selection from Column B (or even A). How do I write this formula in the Data-Validation list?

    1. hello bobby,
      first you wanna a data can put one sheet and go select table you select area change in table and go to formula option select define name first select heading than put name than now per column wise heading not select only heading data select and define name heading wise and use main sheet data validation.

Post a comment



Thanks for your comment! Please note that all comments are pre-moderated, and off-topic ones may be deleted.
For faster help, please keep your question clear and concise. While we can't guarantee a reply to every question, we'll do our best to respond :)