Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Ankeny, Iowa, USA
    Posts
    344
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Contains Function in a Macro (Excel 2007)

    Hi,
    I'm trying to write a bit of code that says if L1 "contains" the letters "Sett-Batch", then cell E1 would result as "ACH" (see code below). Clearly my word "contains" in the code below doesn't work, and I figured it wouldn't, but I didn't know how to go about the contains function as I normally always go with =. Any help is appreciated as always!
    Thanks!
    Lana

    If Sheet3.Range("L" & x) contains "Sett-Batch" Then
    Sheet3.Range("E" & x) = "ACH"

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Contains Function in a Macro (Excel 2007)

    Try this:
    <code>
    If Sheet3.Range("L" & x) Like "*Sett-Batch*" Then
    </code>
    or this:
    <code>
    If InStr(Sheet3.Range("L" & x), "Sett-Batch") > 0 Then</code>

  3. #3
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Ankeny, Iowa, USA
    Posts
    344
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Re: Contains Function in a Macro (Excel 2007)

    Works perfect!
    Thanks Hans!
    Lana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •