+ Reply to Thread
Results 1 to 7 of 7

Macro for Contains

  1. #1
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Ventura, united States
    MS-Off Ver
    Excel 2010
    Posts
    346

    Macro for Contains

    Does anyone know how to program a basic VBA IF statement using Contains.

    Something like this:

    Please Login or Register  to view this content.
    I tried using this:

    Please Login or Register  to view this content.
    It ran the code without error but didn't seem to actually do what I wanted.

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: Macro for Contains

    Take a look at the InStr function.

    Hope this helps.

    Pete

  3. #3
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Macro for Contains

    Jiptastic,

    I'd recommend using the InStr method:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  4. #4
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Ventura, united States
    MS-Off Ver
    Excel 2010
    Posts
    346

    Re: Macro for Contains

    Awesome. I'm off to lunch, but I'll have to try that when I get back.

  5. #5
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Ventura, united States
    MS-Off Ver
    Excel 2010
    Posts
    346

    Re: Macro for Contains

    Doesn't seem to work. I'm not sure how this function is working in order to fix what's wrong. I tried a very simplified version and nothing.

    Please Login or Register  to view this content.
    There isn't a more straightforward "Contains" command?

  6. #6
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Macro for Contains

    It works for me. What do you have in cells A1 and B1?

  7. #7
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Ventura, united States
    MS-Off Ver
    Excel 2010
    Posts
    346

    Re: Macro for Contains

    I had "Hello" in A1 and "Hello 1" in B1, just for a test. I realize now I had it referencing backwards. A1 did not contain B1 in this case. Reversed the two and all is good. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1