+ Reply to Thread
Results 1 to 3 of 3

InStrRev is not working properly when i set the search criteria at "/" Why?

Hybrid View

kjy1989 InStrRev is not working... 10-08-2013, 11:50 PM
protonLeah Re: InStrRev is not working... 10-09-2013, 12:54 AM
AlvaroSiza Re: InStrRev is not working... 10-09-2013, 01:03 AM
  1. #1
    Forum Contributor
    Join Date
    12-03-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    107

    InStrRev is not working properly when i set the search criteria at "/" Why?

    in this string, all is working, it returns 32.

    
    Sub kingama()
    
    Dim TESTNUMBER As Integer
    Dim TESTSTRING As String
    TESTSTRING = "the quick brown fox jumps over the lazy dog"
    
    
    TESTNUMBER = InStrRev(TESTSTRING, "the")
    MsgBox TESTNUMBER
    
    
    
    End Sub
    but when i run this:

    
    Sub TESTING()
    
    Dim TESTNUMBER As Integer
    Dim TESTSTRING As String
    TESTSTRING = "08/10000AF"
    
    TESTNUMBER = InStrRev(TESTSTRING, "/")
    MsgBox TESTNUMBER
    
    End Sub
    this string SHOULD return 8 right? but it doesnt, it returns a value of 3. Why is that so? i find it very unususual and i cannot find a solution to this!

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,936

    Re: InStrRev is not working properly when i set the search criteria at "/" Why?

    INSTRREV started from the end of the string and found the second "the", but it counted from left to right to the 32nd position.
    INSTRREV started from the end of the string and found "/" and counted from left to right to the 3rd position.
    INSTR finds the first occurrence of x, INSTRREV finds the last, there were two "the"'s but only one "/".
    Last edited by protonLeah; 10-09-2013 at 03:53 PM.
    Ben Van Johnson

  3. #3
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: InStrRev is not working properly when i set the search criteria at "/" Why?

    So by that rationale the only way to return 8 is:
    Sub TESTING()
    
    Dim TESTNUMBER As Integer
    Dim TESTSTRING As String
    TESTSTRING = "08/10000AF"
    
    TESTNUMBER = InStr(1, TESTSTRING, "/")
    
    TESTNUMBER = LEN(TESTSTRING) - TESTNUMBER + 1
    
    MsgBox TESTNUMBER
    
    End Sub
    ???
    Perhaps it was the Noid who should have avoided me...
    If you are satisfied with my solution click the small star icon on the left. Thanks
    1. Make a copy of your workbook and run the following code on your copy (just in case)
    2. With excel open, press ALT+F11 to open the Visual Basic Editor (VBE). From the "Insert" menu, select "Module".
    3. Paste the code from above into the empty white space. Close the VBE.
    4. From the developer tab, choose "Macros", select the Sub Name, and click "Run".

+ 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] "next" command button not working properly
    By dpandk in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-10-2012, 11:48 PM
  2. Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)" not working
    By redders in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2011, 03:52 PM
  3. Replies: 5
    Last Post: 08-09-2011, 01:42 PM
  4. "Do Until Loop" not properly working
    By Snoopy2010 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-20-2010, 08:48 AM
  5. Macro "1 tall/1 wide" not working properly
    By gizmo in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-10-2005, 04:06 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