Announcement

Collapse
No announcement yet.

Multiple Criteria in a VBA IF statement

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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:
    Set rSearch = Range("A1", Range("H65536").End(xlUp))
        For Each cl In rSearch
        If CStr(Left(cl.Value, 1)) = "A" & CStr(Left(cl.Value, 2)) = "32" Then Cells(cl.Row, 17).Value = "Offshore"
    "To know the road ahead, ask those coming back."

  • #2
    Re: Multiple Criteria in a VBA IF statement

    Change the & to And.
    Boo!

    Comment


    • #3
      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:
      Set rSearch = Range("C1", Range("C65536").End(xlUp))
          For Each cl In rSearch
          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
      Last edited by Whovian Zorker; May 11th, 2006, 01:01.
      >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 ***

      Comment


      • #4
        Re: Multiple Criteria in a VBA IF statement

        Brian

        Good catch!
        Boo!

        Comment


        • #5


          Re: Multiple Criteria in a VBA IF statement

          Works great! Thanks a ton to both of you.
          "To know the road ahead, ask those coming back."

          Comment

          Working...
          X