+ Reply to Thread
Results 1 to 7 of 7

Instr() function

  1. #1
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Instr() function

    Hello,

    I have two columns that require dropdown lookup and I would like excel to tell me if the string is found in the dropdown.

    here is the code:

    Please Login or Register  to view this content.
    No matter what values I select from the dropdown, col C won't give me anything. The instr() functions above will check to see if the string is found in the dropdown, correct?

    Can anybody point me in the right direction?

    Thank you
    Attached Files Attached Files
    Last edited by Lifeseeker; 12-20-2011 at 04:00 PM.

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Instr() function VBA

    Hi Lifeseeker,

    I downloaded your file, enabled macros and when I select options from the drop-downs in columns A/B on the MAIN worksheet, column C fills in accordingly. Are your Events or macros disabled prior to the triggering of the code? To make sure they're on, open a blank workbook and add the following code to a module. Run it, then open your workbook (enable macros if necessary) and try again.

    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Instr() function VBA

    Hi Paul,

    I thought I had that line in there.

    Please Login or Register  to view this content.
    Excel won't execute it even after I enable the macro.

    Do you have to open a blank workbook and add that condition every time you open this file?

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Instr() function

    You shouldn't have to run that code unless macros have been disabled via code previously.

    I simply download your file, open it, and I am prompted to enable macros. I do so, then select a value in cell A5 and C5 is then populated. Nothing else to do, it just works. You may want to check that you don't have macros disabled without notification in Excel Options > Trust Center > Trust Center Settings... > Macro Settings. A safe setting is "Disable all macros with notification". That will prompt you with a message beneath the ribbon when you open the workbook to enable macros. If it's set to "Disable all macros without notification", no macros will run and you won't be prompted to enable them anyway.

    Don't set it to "Enable all macros..." to prevent a malicious macro from running on your PC.

  5. #5
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Instr() function VBA

    Hi,

    The 3rd column is beginning to fill ,which is good, but it seems that one of the values from the dropdown won't cause Excel to fill "yes" on column C. It is supposed to say "Yes" because it is a direct match?

    Please see the attached file

    Please Login or Register  to view this content.
    The first choice and 2nd both returns a "No", only the last selection will return "yes". They all suppose to return "yes" because it is a direct match, but Excel is giving me a different answer.

    In addition, if I type up some random characters such as "Altered", Excel won't give me "Yes". It is supposed to give me a "Yes" because "Altered" is found in one of the dropdown selections.

    Could anyone help out?

    Thanks
    Attached Files Attached Files

  6. #6
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Instr() function

    Add one line of code to your If InStr function to exit the For/Next loop if a match is found ("Yes"). Without exiting the For/Next loop, the value in the cell you just changed is then sequentially compared with the rest of the cells in the dropdowns column, almost certainly resulting in "No".
    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Instr() function

    Ah I see...

    Hmm that takes experience to know definitely...thank you Paul.

    I actually thought I would be okay even if I were to do an exact comparison instead of using InStr(). So far so good.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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