+ Reply to Thread
Results 1 to 10 of 10

Like Operator in Simple Macro

  1. #1
    Forum Contributor
    Join Date
    04-20-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    160

    Like Operator in Simple Macro

    Hi,

    I want to use the Like Operator within an IF Statement. I created some code below that if a user tries to name a new worksheet using the these characters

    :\/?*[]

    then my message custom error message will come up.

    Here is my code below:

    Please Login or Register  to view this content.
    Thank you,

    BC
    Last edited by boldcode; 04-22-2013 at 10:40 PM. Reason: Solved

  2. #2
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Like Operator in Simple Macro

    This maybe,

    Please Login or Register  to view this content.
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Like Operator in Simple Macro

    Hi,

    See if http://www.bettersolutions.com/vba/V...T218312322.htm explains how to do individual character matches using VBA.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    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: Like Operator in Simple Macro

    Hello boldcode,

    The best method is to use Regular Expressions when checking for multiple characters. This macro will return True Or False after testing the file name for special characters. True if there are no invalid characters or False if there are.
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 04-22-2013 at 09:05 PM.
    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!)

  5. #5
    Forum Contributor
    Join Date
    04-20-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Like Operator in Simple Macro

    Hi Leith,

    How do I use your function within my if statement? The reason I ask is because I expanded my macro into multiple if statements as shown below:

    Please Login or Register  to view this content.
    I appreciate the help!

  6. #6
    Forum Contributor
    Join Date
    04-20-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Like Operator in Simple Macro

    JapanDave,

    Thank you very much, your code works!

    - BC

  7. #7
    Forum Contributor
    Join Date
    04-20-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Like Operator in Simple Macro

    MarvinP,

    Thank you, I will check out the link.

    - BC

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,633

    Re: Like Operator in Simple Macro

    Just change the line
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    04-20-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Like Operator in Simple Macro

    jindon,

    Awesome, thank you!

    - BC

  10. #10
    Forum Contributor
    Join Date
    04-20-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Like Operator in Simple Macro

    Leith Ross,

    Thank you again, I marked the post as Solved.

    - BC

+ 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