+ Reply to Thread
Results 1 to 4 of 4

Want to use VBA to format and validate cell content

  1. #1
    Registered User
    Join Date
    12-23-2014
    Location
    Wisconsin, USA
    MS-Off Ver
    2013
    Posts
    3

    Want to use VBA to format and validate cell content

    Hi all,

    My request is similar to this one: http://www.excelforum.com/excel-form...l-content.html

    I'm looking to create data validation as well as format the input for a cell, according to these stipulations:
    -The data will be formatted as XXX-######
    -Any of the first 3 characters before the dash are either alpha or numeric
    -The last 6 characters after the dash are always numeric
    -The user should be able to enter or not enter the dash, (if not then the code should insert it for them)
    -If there are not exactly 9 characters (or 10 if the dash is present) or if there are special characters or if the last 6 characters contain alpha, a warning box should follow.

    I'm not familiar enough with VBA syntax to code this myself.

    Thanks in advance for your assistance.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Want to use VBA to format and validate cell content

    This works fo A8:A27 and E18 to E27

    right click on the file name at the bottom of excel

    select view code and paste there.

    Close the vba window.

    Please Login or Register  to view this content.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    12-23-2014
    Location
    Wisconsin, USA
    MS-Off Ver
    2013
    Posts
    3

    Re: Want to use VBA to format and validate cell content

    Wow thanks for the quick reply!

    Code works great with initial testing (so far i've added to the length check to test for values that are too short as well). I'm out until next week for the holiday, and will test further and report back with any questions/and mark it closed then.

    Again, thank you very much for your time!

  4. #4
    Registered User
    Join Date
    12-23-2014
    Location
    Wisconsin, USA
    MS-Off Ver
    2013
    Posts
    3

    Re: Want to use VBA to format and validate cell content

    Ok, so I have an issue:

    If the user enters data into the target cell, then deletes the data, then re-enters data that should cause an action, the action no longer will occur. I think that this might have to do with the errorflag status not getting reset, but I'm not sure and I've been unable to get it working. Here's my modified code thus far (I've changed the target range and changed the length check as mentioned).

    Please Login or Register  to view this content.
    Thanks again.

+ 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. [SOLVED] Validate cell value- format (for use in Password)
    By jdlc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-20-2012, 02:21 PM
  2. Enforce/Validate cell format
    By girish.ramjuttun in forum Excel General
    Replies: 1
    Last Post: 10-31-2011, 06:04 AM
  3. Lock Cell Date Format NOT Content
    By mlmaclean in forum Excel General
    Replies: 4
    Last Post: 12-30-2010, 08:00 AM
  4. Cell Content and Format to VBA
    By mohitp in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-31-2009, 04:11 AM
  5. Replies: 5
    Last Post: 03-10-2005, 08:06 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