Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6821637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:34:05+00:00 2026-05-26T21:34:05+00:00

I have the following INSTR condition in Excel VBA which doesn’t work (all the

  • 0

I have the following INSTR condition in Excel VBA which doesn’t work (all the time)

STR_TEXT="SKU1234 $100/10'  $200/20'"  ' < example string

IF INSTR(STR_TEXT,"/10'") AND INSTR(STR_TEXT,"/20'") THEN
  ' code
ELSE
  ' code
END IF

For some obscure reason, it seems like it cannot check for both conditions so the first IF, even if both condition match, doesn’t seem to work and goes to ELSE.

The following does work:

STR_TEXT="SKU1234 $100/10'  $200/20'"  ' < example string

IF INSTR(STR_TEXT,"/10'") THEN
       IF INSTR(STR_TEXT,"/20'") THEN
               ' code
       END IF
ELSE
  ' code
END IF

As you can see, if I separate the conditions on the first IF, it works.
But I would prefer to have both conditions in same IF, as code is ‘cleaner’.

Anyone knows why and/or how to fix it without having to put an IF inside another IF ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:34:06+00:00Added an answer on May 26, 2026 at 9:34 pm

    EXMAPLE:

    if instr(str_Text,"/10'") > 0 AND instr(str_text,"/20'") > 0 then
    

    What Tim is saying is that the instr function returns the position in the string of the first instance of the string being searched for..

    so in your example: 13 is being returned for instr(str_Text,”/10′).

    When VBA reads your version instr(str_text,”/10;”) (without the >0) then it sees that the result is not 1 (which means true) so it always hits the else)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following macro which needs to loop though an Excel-2007 table. The
I have the following condition If InStr(a,b,c, stringA) > 0 OrElse (InStr(y,z, stringB) >
I have following Code Block Which I tried to optimize in the Optimized section
I have an interface which is used like the following: if (SUCCEEDED(pInterface->GetSize(&size)) { wchar_t
I have written the following code which works, but im wondering can I make
I have the following MyType::Is_Inst () function which is throwing an invalid memory access
I have the following Ruby script, in which class Foo includes module Baz, module
I have the following code which check password/login and do other actions: public virtual
I want to make the following: when the url doesn't have an instID, i
I have following situation: I have loged user, standard authentication with DB table $authAdapter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.