+ Reply to Thread
Results 1 to 5 of 5

Code to check if cell value start with int.

Hybrid View

  1. #1
    Registered User
    Join Date
    09-14-2011
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    64

    Code to check if cell value start with int.

    Hi.

    I have a little problem I cant find a solution to.

    I want to use some kind of if statement to check if a cell contains a word starting wiht "int" or "Int"
    Cell value can be Intern, international, Internet, Intranet, Intellect, interesting or any other word starting with "int"
    I tried:
    If Sheets("Sheet1").Range("A1") = "Int*" Or Sheets("Sheet1").Range("A1") = "int*" Then
    MsgBox ("Yes!")
    Else
    MsgBox ("No!")
    End If
    But it sems like the wildcard * doesn't work here.
    How do I do this?

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Code to check if cell value start with int.

    Option Explicit
    Option Compare Text
    
    Sub tt()
    If Range("A1").Value Like "int*" Then MsgBox "Yes!" Else MsgBox "No!"
    End Sub

  3. #3
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Code to check if cell value start with int.

    try using "like"
    Sub test()
    If Sheets("Sheet1").Range("A1") Like "Int*" Or Sheets("Sheet1").Range("A1") Like "int*" Then
    MsgBox ("Yes!")
    Else
    MsgBox ("No!")
    End If
    End Sub
    Last edited by martindwilson; 11-23-2012 at 07:22 AM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  4. #4
    Valued Forum Contributor
    Join Date
    03-17-2012
    Location
    Warsaw, Poland
    MS-Off Ver
    2007/2010
    Posts
    555

    Re: Code to check if cell value start with int.

    Sub lol()
    
    If Mid(Range("A1"), 1, 3) = "int" Then
        MsgBox "yes"
        Else
        MsgBox "no"
    End If
    
    End Sub
    If you think that my answer was helpful, please click on the "Add to this user's Reputation" button.

  5. #5
    Registered User
    Join Date
    09-14-2011
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    64

    Re: Code to check if cell value start with int.

    Ah!!

    Why didn't I come up with the Like function. Been using that long time ago.
    Thanks a thousand times to all you who replied.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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