+ Reply to Thread
Results 1 to 5 of 5

VBA "contains" or "like" statement?

  1. #1
    Forum Contributor
    Join Date
    04-03-2014
    Location
    Berlin
    MS-Off Ver
    Excel 2010
    Posts
    160

    VBA "contains" or "like" statement?

    Hey Guys,

    I'm trying to write a simple VBA statement to identify if a cell contains a certain string, rather than the entire string being equal or not equal to a value.
    Whereas the Statement works for "SW" and "PM" as they are always situated in the beggining of the string, when it comes to checking whether the string contains "VERR" or "wegfall" the statement does not find/recognize them and therefore it does not return the specified "1".

    Your suggestions are very much appreciated! many thanks ;-)

    [] With ws1
    With Range("AY7:AY" & Range("A" & Rows.count).End(xlUp).Row)
    .Formula = "=IF(LEFT(M7,2)=""SW"","""",IF(LEFT(M7,2)=""PM"","""",IF((M7)="" * VERR * "","""",IF((M7)="" * wegfall * "","""",""1""))))"
    '.Value = .Value
    .FormatConditions.Delete
    .FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
    Formula1:="="""""
    .FormatConditions(1).Font.ColorIndex = 3
    End With
    End With [/]

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437

    Re: VBA "contains" or "like" statement?

    You could try this formula which uses FIND to check for subtext within text. use SEARCH if you are not bothered about case sensitivity.

    =IF(OR(LEFT(M7,2)="SW",LEFT(M7,2)="PM",IFERROR(FIND("VERR",M7)>0,FALSE),IFERROR(FIND("wegfall",M7)>0,FALSE)),"","1")

    For VBA you will need to double up on the quotes. as per your example.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    861

    Re: VBA "contains" or "like" statement?

    Hello,

    VBA supports Like operator : here
    I also recommend using Instr VBA function
    .. and don't forget to have fun!
    Bogdan.

    mark SOLVED and Add Reputation if my answer pleases you

  4. #4
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: VBA "contains" or "like" statement?

    You could use this formula:
    =IF(OR(LEFT(M7,2)="SW",LEFT(M7,2)="PM",ISERR(SEARCH("VERR",M7))=FALSE,ISERR(SEARCH("wegfall",M7))=FALSE),"","1")

    Regards,
    Antonio

  5. #5
    Forum Contributor
    Join Date
    04-03-2014
    Location
    Berlin
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: VBA "contains" or "like" statement?

    Perfect! Thanks a lot! ;-)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 08-15-2014, 06:00 AM
  2. Replies: 4
    Last Post: 11-17-2013, 12:05 PM
  3. [SOLVED] How to USE """"" cells count """"" change font color
    By austin123456 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2013, 06:14 AM
  4. Replies: 5
    Last Post: 10-12-2010, 06:46 AM
  5. Replies: 3
    Last Post: 12-14-2006, 01:36 PM
  6. Replies: 5
    Last Post: 06-26-2006, 09:23 PM
  7. Replies: 7
    Last Post: 05-13-2006, 05:02 PM

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