+ Reply to Thread
Results 1 to 3 of 3

String Comparison Within IF Statement VBA

  1. #1
    Registered User
    Join Date
    05-03-2019
    Location
    San Francisco
    MS-Off Ver
    7
    Posts
    28

    String Comparison Within IF Statement VBA

    Hello,

    I am wondering what would be the cleanest way to accomplish the following string comparison task. I want to use an if statement to compare a single string to a group of strings, and output a message if true or do nothing if false. For example..

    (I know the IN operator won't get this done in Excel, but I'd rather find something shorter than a bunch if IF ELSE)

    IF "mystring" <> IN ("excel","is","cool")
    THEN MsgBox "Error!"
    END IF


    Cheers!

  2. #2
    Banned User!
    Join Date
    01-17-2021
    Location
    Omaha, NE
    MS-Off Ver
    office 2016
    Posts
    211

    Re: String Comparison Within IF Statement VBA

    if you want compare to see if YOUR string in a group of strings, you dont even need complex functions. just put the strings together as one long and use instr or mid. like this

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-03-2019
    Location
    San Francisco
    MS-Off Ver
    7
    Posts
    28

    Re: String Comparison Within IF Statement VBA

    I think you have the argument for instr mixed up but thank you for leading me to the answer!

+ 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] String Comparison
    By ihop72 in forum Excel Formulas & Functions
    Replies: 24
    Last Post: 01-15-2021, 02:30 PM
  2. Excel 2007 : text string comparison
    By pedro4545 in forum Excel General
    Replies: 0
    Last Post: 10-21-2011, 11:33 AM
  3. String Comparison
    By tactical in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-13-2011, 01:15 PM
  4. String comparison
    By HurricaneDan in forum Excel General
    Replies: 4
    Last Post: 11-08-2006, 02:05 PM
  5. comparison string VBA excell
    By stats in forum Excel General
    Replies: 5
    Last Post: 03-16-2006, 06:15 PM
  6. HELP: Comparison IF statement
    By R Weeden in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-06-2006, 05:00 PM
  7. String Comparison
    By Purnima in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-08-2005, 08:06 AM

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