+ Reply to Thread
Results 1 to 7 of 7

Use formatting rules to require and restrict data in cells

  1. #1
    Forum Contributor
    Join Date
    05-01-2013
    Location
    Richmond, VA
    MS-Off Ver
    Excel 365
    Posts
    164

    Use formatting rules to require and restrict data in cells

    How would I add either via a macro or Data Validation formula rules in Excel 2010 for two columns with different value needs? Please find the details listed below:

    Cells in Column B need look like this: "N1234" with the first character being alpha and the next four characters being numeric
    Cells in Column C need to look like this: "AB1201" with the first two characters being alpha and the last four being numeric

    I will format the entire column with these rules and as people enter their data the data will need to conform to these rules or the user will be unable to successfully enter the data. I am using Excel 2010.

    Any help with this would be greatly appreciated.

  2. #2
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Use formatting rules to require and restrict data in cells

    You can do this with Data Validation.

    Highlight B2:B10 (or however far you want to go) > Data > Data Validation > Allow: Custom > Formula: =AND(ISERROR(LEFT(B2)+0),ISNUMBER(RIGHT(B2,4)+0),LEN(B2)=5) > OK

    Highlight C2:C10 (or however far you want to go) > Data > Data Validation > Allow: Custom > Formula: =AND(ISERROR(LEFT(C2,2)+0),ISNUMBER(RIGHT(C2,4)+0),LEN(C2)=6) > OK

  3. #3
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,885

    Re: Use formatting rules to require and restrict data in cells

    Alpha validation is tricky. While ISERROR(LEFT(C2,2)+0) will return true for "AB" it will also return true for "A1", "?A" etc.

    Assuming only A-Z are allowed something like below for C2:C10 range.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  4. #4
    Forum Contributor
    Join Date
    05-01-2013
    Location
    Richmond, VA
    MS-Off Ver
    Excel 365
    Posts
    164

    Re: Use formatting rules to require and restrict data in cells

    Hello,

    When I try to use the formula for column B and the formula for column C the following error appears for both: "A named range you specified cannot be found." Since the data validation begins on row 21 (cell B21 and cell C21) I changed B2 and C2 in your formula to B21 and C21, respectively.

  5. #5
    Forum Contributor
    Join Date
    05-01-2013
    Location
    Richmond, VA
    MS-Off Ver
    Excel 365
    Posts
    164

    Re: Use formatting rules to require and restrict data in cells

    Hello, this formula works for column C - I just modified it slightly to begin at cell C21. Thank you! That said, can you help with column B (which actually starts with B21)? I tried to modify what you provided for C as follows:

    =AND(MEDIAN(CODE(LEFT(B21,1)),65,90)=CODE(LEFT(B21,1)),MEDIAN(CODE(MID(B21,2,1)),65,90)=CODE(MID(B21,2,1)),ISNUMBER(RIGHT(B21,2)+0),LEN(B21)=4)

    However, I am sure I missed something. Column B example is: N1234 - First character is alpha value and the next four characters are numeric values.

  6. #6
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,885

    Re: Use formatting rules to require and restrict data in cells

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

    You don't need second Median()=CODE() part, as that's checking if 2nd character is A-Z.

  7. #7
    Forum Contributor
    Join Date
    05-01-2013
    Location
    Richmond, VA
    MS-Off Ver
    Excel 365
    Posts
    164

    Re: Use formatting rules to require and restrict data in cells

    OMG! Thank you these both work!

+ 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. Deleted Post
    By Hedy in forum Excel General
    Replies: 1
    Last Post: 08-30-2018, 03:28 PM
  2. Replies: 1
    Last Post: 08-31-2014, 03:38 PM
  3. Automatic formatting of cells based on rules/criteria
    By ioannes in forum Excel General
    Replies: 1
    Last Post: 07-30-2014, 03:55 AM
  4. Conditional formatting rules linking to cells
    By Mountain99 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-11-2013, 10:35 AM
  5. Replies: 1
    Last Post: 06-12-2013, 10:23 AM
  6. Replies: 2
    Last Post: 06-23-2011, 01:19 AM
  7. restrict with rules
    By mqdias in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-29-2006, 12:02 PM

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