+ Reply to Thread
Results 1 to 14 of 14

VBA IF with OR

  1. #1
    Registered User
    Join Date
    11-21-2015
    Location
    france
    MS-Off Ver
    2010
    Posts
    57

    VBA IF with OR

    Hi everyone !

    I can't understand why my 2nd condition with "OR" is not taking into account.
    That is to say, that it puts in color "FR" but not "NL" :


    Please Login or Register  to view this content.

    Thank you very much in advance for your help

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,595

    Re: VBA IF with OR

    Perhaps
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    11-21-2015
    Location
    france
    MS-Off Ver
    2010
    Posts
    57

    Re: VBA IF with OR

    Thank you very much Jindon ! It is working BUT only if I open my VBA window with in the background the workbook "wk49production"
    However my bouton command is on another workbook..I guess It's a problem of "calling" the workbook ?

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA IF with OR

    Hi,

    If you're using the Instr this returns the position in the string being searched. Hence you need to test whether the position is >0. e.g.

    If (InStr(1, Celltxt, "FR") > 0 .....etc
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,595

    Re: VBA IF with OR

    Do you mean "Cells(x, 10) = 6" this part?

    or it doesn't work when "wk49production" is closed?
    Last edited by jindon; 11-29-2015 at 07:13 AM.

  6. #6
    Registered User
    Join Date
    11-21-2015
    Location
    france
    MS-Off Ver
    2010
    Posts
    57

    Re: VBA IF with OR

    I have this macro on another workbook. If I press my bouton command it is not working.

    However, If I open the Visual Editor, with in the background my workbook "Wk49production", then It is working perfectly.

    Can't understand why, as I am mentionning "Set db = Workbooks("wk49production")"

  7. #7
    Registered User
    Join Date
    11-21-2015
    Location
    france
    MS-Off Ver
    2010
    Posts
    57

    Re: VBA IF with OR

    My problem of workbook is solved, I have changed a few brackets :

    Please Login or Register  to view this content.

    But no "NL" in color ("FR" still fine)

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,595

    Re: VBA IF with OR

    I have tested in the like situation and worked as it should....

  9. #9
    Registered User
    Join Date
    11-21-2015
    Location
    france
    MS-Off Ver
    2010
    Posts
    57

    Re: VBA IF with OR

    Unfortunately no..If I have "NL" in one cell and "6" on the other cell (same row), it won't color

  10. #10
    Registered User
    Join Date
    11-21-2015
    Location
    france
    MS-Off Ver
    2010
    Posts
    57

    Re: VBA IF with OR

    I have just tried to put "NL" in the first postion and it would work fine, but not with "DE" which would be 2nd position.
    So there's a problem with my "OR" statement I reckon.

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,595

    Re: VBA IF with OR

    See the attached
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    11-21-2015
    Location
    france
    MS-Off Ver
    2010
    Posts
    57

    Re: VBA IF with OR

    Thank you so much Jindon for taking the time to help me. Much appreaciated.

    The thing is that I have "NL" and "DE" on workbook Wk49Production, but also the "6" on this same workbook. (so when I have "NL", and 6 on same row = color)

    (My macro is stored in another workbook, with my button command)

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,595

    Re: VBA IF with OR

    Do you mean
    Please Login or Register  to view this content.
    ?

  14. #14
    Registered User
    Join Date
    11-21-2015
    Location
    france
    MS-Off Ver
    2010
    Posts
    57

    Re: VBA IF with OR

    Jindon you're the man !

    Sorry I should have explained more in details from the start.
    A HUGE thank you to all of you for the time you spent helping me.

    And thank you again Jindon !

+ 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