Multiple Criteria in a VBA IF statement

  • In column C I have a number ex. AB0-111-111111-00, and in column H I have numbers 1-32. If the contents of column C begins with "A", and column H contains 32, then in the corresponding cell in Column Q I want it to paste "offshore". I have this statement began but i obviously have some errors in it. Any help is greatly appreciated.


    Code
    1. Set rSearch = Range("A1", Range("H65536").End(xlUp))
    2. For Each cl In rSearch
    3. If CStr(Left(cl.Value, 1)) = "A" & CStr(Left(cl.Value, 2)) = "32" Then Cells(cl.Row, 17).Value = "Offshore"
  • Re: Multiple Criteria in a VBA IF statement


    Also, you are checking each cell individually in this range. So (for instance) it checks to see if the leftmost character of A1 is "A", and if the leftmost two characters of A1 are "32". I can guarantee you that this is impossible in this universe. ;) How about this variation (untested):


    Code
    1. Set rSearch = Range("C1", Range("C65536").End(xlUp))
    2. For Each cl In rSearch
    3. If CStr(Left(cl.Value, 1)) = "A" And CStr(Left(cl.Offset(0,5).Value, 2)) = "32" Then cl.Offset(0,14).Value = "Offshore"


    Brian

    >DISABLE DALEK WITH SONIC SCREWDRIVER
    The batteries have gone flat. I told you that you should have changed them after you spent ten hours debugging it in the TARDIS. But did you listen? Noooooooo...


    The Dalek notices your presence for the first time, and reacts normally.
    "EXTERMINATE! EXTERMINATE!"


    *** You have been exterminated ***