+ Reply to Thread
Results 1 to 6 of 6

String Match & Special Characters

  1. #1
    Registered User
    Join Date
    07-12-2010
    Location
    BC Canada
    MS-Off Ver
    Excel 2007
    Posts
    5

    String Match & Special Characters

    Hi,

    I'm looking for a function, that will look at a row of values in column b (for example) to see if it complies with approved naming convention. Naming convention must be as follows: <6 numbers><Single Space><Alpha with or without spaces>

    If compliance is met, then do nothing. If compliance isn't met (error), place an 'x' in column a.

    Example of Good:
    555555 Food
    555789 Red Apple
    123456 I Love Excel

    Example of Bad (to illustrate)
    555555Food (no space between number and word)
    555789 Red!Apple (special character)
    I Love Excel 123456 (number at end, alpa at start)
    55555 Smith (only 5 numbers at start)
    555-123 Smich (first 6 characters not numeric)

    Can anyone help me with a function / macro?

    Thank you very much.

    Cam.
    Last edited by camikins; 07-13-2010 at 02:11 PM.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: String Match & Special Characters

    Cam

    Here's a function that will return "ERROR" if it doesn't match the pattern, or a blank if it does.

    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor
    Join Date
    10-15-2007
    Location
    Home
    MS-Off Ver
    Office 2010, W10
    Posts
    373

    Re: String Match & Special Characters

    Hi Cam

    Similar to rylo's, but makes sure that there is at least 1 alpha and that all the rest of the characters to the end of string are alpha or spaces.

    Returns True if the string is valid, False otherwise:

    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor
    Join Date
    10-15-2007
    Location
    Home
    MS-Off Ver
    Office 2010, W10
    Posts
    373

    Re: String Match & Special Characters

    An equivalent solution, without using RegExp's is to compare the value directly with a pattern:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-12-2010
    Location
    BC Canada
    MS-Off Ver
    Excel 2007
    Posts
    5

    Red face Re: String Match & Special Characters

    Thanks very much!
    All three were good solutions. I've gone with a hybrid of them all which does exactly what I want.

    Code:
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 07-13-2010 at 01:32 PM. Reason: Added Code Tags

  6. #6
    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: String Match & Special Characters

    Hello camikins,

    To make your posts easier to read, copy, and edit please wrap your code. I did it for you this time. Here is how you can do it next time.

    How to wrap your Code using the # icon
    1. Select all your code using the mouse.
    2. Click on the # icon on the toolbar in the Message window. This will automatically wrap the text you selected with the proper Code tags to create a Code Window in your post.

    To manually wrap your code, use these Bulletin Board Code Tags
    [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] at the end of the last line.


    To learn more about BB codes used in this forum, just click on the link below...

    Bulletin Board Codes Tags
    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!)

+ 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