• Contains Function in a Macro (Excel 2007)

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Contains Function in a Macro (Excel 2007)

    Author
    Topic
    #457646

    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”

    Viewing 0 reply threads
    Author
    Replies
    • #1148106

      Try this:

      If Sheet3.Range("L" & x) Like "*Sett-Batch*" Then

      or this:

      If InStr(Sheet3.Range("L" & x), "Sett-Batch") > 0 Then

    Viewing 0 reply threads
    Reply To: Contains Function in a Macro (Excel 2007)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: