+ Reply to Thread
Results 1 to 7 of 7

If condition not working with InStrRev

  1. #1
    Forum Contributor
    Join Date
    05-30-2013
    Location
    France
    MS-Off Ver
    2010
    Posts
    260

    If condition not working with InStrRev

    Hi,

    I'm trying to check if the string has a backslash at the end. However my if condition which checks if the slash is present is not working properly. My code immediately skips to the second msgbox...any help would be great.

    Please Login or Register  to view this content.
    Thanks,
    amphi

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: If condition not working with InStrRev

    There is not slash in mystring so it skips.

  3. #3
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: If condition not working with InStrRev

    It works perfectly according to your description - it only shows the first MsgBox if the string does contain a '\'

    Why would you use InStrRev for this? The basic InStr() function would give the same result.
    Last edited by cytop; 04-09-2014 at 04:58 AM.

  4. #4
    Forum Contributor
    Join Date
    05-30-2013
    Location
    France
    MS-Off Ver
    2010
    Posts
    260

    Re: If condition not working with InStrRev

    Sorry guys had a brain freeze. Thanks the instr() is perfectly ok for this.

  5. #5
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: If condition not working with InStrRev

    Quote Originally Posted by cytop View Post
    Why would you use InStrRev for this? The basic InStr() function would give the same result.
    Actually InStrRev is better now because InStr will return wrong result for mystring = "Hi I'm \ a string"
    But for that it would need aditional check that InStrRev result is same as Len(mystring)

  6. #6
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: If condition not working with InStrRev

    Or just this:
    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: If condition not working with InStrRev

    If you are "...trying to check if the string has a backslash at the end" (post #1) then
    Please Login or Register  to view this content.
    or some variation thereof.

    You could also get rid of a couple of lines of code
    Please Login or Register  to view this content.
    (Essentially the same as the previous post).

    None is 'more right' than the other - the primary concern is readability.

+ 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. InStrRev is not working properly when i set the search criteria at "/" Why?
    By kjy1989 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-09-2013, 01:03 AM
  2. [SOLVED] worksheet function for InStrRev()
    By Martin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-11-2013, 07:23 PM
  3. Help need to extract a part of string - InstrRev
    By ragavendraph in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-10-2012, 09:45 AM
  4. InStrRev - Compile Error
    By Apel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-10-2008, 04:49 PM
  5. Instrrev function
    By DavidC in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-22-2006, 07:35 PM

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