+ Reply to Thread
Results 1 to 5 of 5

VBA to determine if Federal ID or Social Security #

  1. #1
    Forum Contributor
    Join Date
    06-23-2005
    Posts
    253

    VBA to determine if Federal ID or Social Security #

    What would be the simplest VBA to determine if a cell E7 contains:

    A federal ID always 9 digits with only one hyphen which is always after the 1st two numbers. For example: 12-3456789

    or

    A social security number always 9 digits with only two hyphens which are always 1 hyphen after the 1st 3 numbers & the other hyphen after the next 2 numbers. For example 123-45-6789.

    In other words,

    If Range("E7") = a federal id then
    or
    If Range("E7") = a social security number then

    I really appreciate your help. mikeburg
    Last edited by mikeburg; 01-30-2010 at 12:57 PM.

  2. #2
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: VBA to determine if Federal ID or Social Security #

    Since the first hyphen is always either the third character or fourth, you only need to check this character once.

    Please Login or Register  to view this content.
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA to determine if Federal ID or Social Security #

    Hello Mikeburg,

    You can use a UDF to validate the cell contents using the Like operator for pattern matching.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: VBA to determine if Federal ID or Social Security #

    Or ...
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Forum Contributor
    Join Date
    06-23-2005
    Posts
    253

    Re: VBA to determine if Federal ID or Social Security #

    Hey, thanks a million for your help! This answers my question. They work great! mikeburg

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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