+ Reply to Thread
Results 1 to 7 of 7

IF Cell.Value partly equals

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-16-2011
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    405

    Question IF Cell.Value partly equals

    Hi all, hope your doing well

    I need help with 'looking' at part of the value of a cell.

    I am looking down a column for a specific term - 'Ford' - however these values cannot be found as my cells have extra data in them such as 'Ford1965' or 'FordRacing' etc etc

    How can i get VBA to use a function such as Left(A1,4) to check if the first # of characters match my search term?

    Regards

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

    Re: IF Cell.Value partly equals

    Maybe InStr?
    something like
    If InStr(Range("A1"), "Ford") Then MsgBox "found"

  3. #3
    Forum Contributor
    Join Date
    11-16-2011
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    405

    Re: IF Cell.Value partly equals

    Thank you Nilem

    how do i modify this such that it works in the example below..
    For Rw = 1 To Range("C" & Rows.Count).End(xlUp).Row
        With Range("C" & Rw)
        
            If .Value = InStr("C" & Rw), "Fld Coordinator") Then MsgBox "found"
                .Cut Range("B" & Rw)

  4. #4
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: IF Cell.Value partly equals

    You can use this code


    If Left(Range("A13"), 4) = "Ford" Then [B13] = "Y"
    or this

    Selection.Find(What:="ford*", After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Activate

  5. #5
    Forum Contributor
    Join Date
    11-16-2011
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    405

    Re: IF Cell.Value partly equals

    Thank you kvsrinivasamurthy i got it working using your first example.
    But now another Issue has arrised..

    
    For Rw = 1 To Range("C" & Rows.Count).End(xlUp).Row
        With Range("C" & Rw)
        
            If Left(Range("C" & Rw), 15) = "Fld Coordinator" Then
                  .Cut Range("A" & Rw)
            End If
    whilst I am in a With Range is it possible to move .cut a row outside of this range..
    i.e. once the condition for the If statment above are met then how can i cut not only the Range("A" & Rw) but also 1 row above and 1 row below Rw ?

  6. #6
    Forum Contributor
    Join Date
    11-16-2011
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    405

    Re: IF Cell.Value partly equals

    Solved, Called to another sub routine. thanks guys!

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

    Re: IF Cell.Value partly equals

    Sub ert()
    Dim Rw&
    For Rw = 1 To Range("C" & Rows.Count).End(xlUp).Row
        With Range("C" & Rw)
            If InStr(.Value, "Fld Coordinator") Then .Cut Range("B" & Rw)
        End With
    Next
    End Sub

+ 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