Announcement

Collapse
No announcement yet.

Multiple Criteria in a VBA IF statement

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

  • cbanks
    started a topic Multiple Criteria in a VBA IF statement

    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"

  • cbanks
    replied
    Re: Multiple Criteria in a VBA IF statement

    Works great! Thanks a ton to both of you.

    Leave a comment:


  • norie
    replied
    Re: Multiple Criteria in a VBA IF statement

    Brian

    Good catch!

    Leave a comment:


  • Whovian Zorker
    replied
    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.

    Leave a comment:


  • norie
    replied
    Re: Multiple Criteria in a VBA IF statement

    Change the & to And.

    Leave a comment:

Working...
X