Results 1 to 4 of 4

Thread: VBA for Excel 2013: Instr produces incorrect result

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2016
    Posts
    3

    VBA for Excel 2013: Instr produces incorrect result

    dim a
    a="CREATE MENU [Staging].[OAs] AS"
    ?instr(a,"AS"), len(a)
    29

    a=lcase("CREATE MENU [Staging].[OAs] AS")
    ?instr(a,"as")
    25

    a=ucase("CREATE MENU [Staging].[OAs] AS")
    ?instr(a,"AS")
    25

    Why the difference when using ucase or lcase, missing the correct position by exactly 4 characters? Anyone?

    Nico

  2. #2

    Thread Starter
    New Member
    Join Date
    May 2016
    Posts
    3

    Re: VBA for Excel 2013: Instr produces incorrect result

    Sorry, the third line should not have ", len(a)"
    It reported 30, anyway.

  3. #3
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: VBA for Excel 2013: Instr produces incorrect result

    Because ucase converts the [OAs] to [OAS], and the "AS" in the brackets starts in position 25.

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2016
    Posts
    3

    Re: VBA for Excel 2013: Instr produces incorrect result

    Quote Originally Posted by vbfbryce View Post
    Because ucase converts the [OAs] to [OAS], and the "AS" in the brackets starts in position 25.
    Funny how one's mind is made up beforehand what to expect. Especially when it's late and one is tired.

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width