+ Reply to Thread
Results 1 to 4 of 4

Find a specific string in a cell

Hybrid View

  1. #1
    loren.pottinger
    Guest

    Find a specific string in a cell

    I would like to search all the cells that are not empty in column E for
    the words Account and New. If the cell does not have either of those
    words in it, I would like to delete that entire row, go to the next
    cell in column E and repeat this action until I arrive at an empty
    cell.

    Please help

    LP


  2. #2
    Forum Contributor
    Join Date
    11-11-2005
    Posts
    267
    sub n()
    dim c as range
    set rng = Range("e1",Cells(rows.count,"e").end(xlUp))
    for each c in rng
    if c.value="Account" or c.value="New" then
    c.entirerow.delete
    end if
    next
    end sub


    hth
    myles

  3. #3
    loren.pottinger
    Guest

    Re: Find a specific string in a cell

    Hey Myles. Thanks for the reply. I attempted that but it didn't exactly
    work. I believe that I am leaving out some pertinent information. The
    cells that I searching do not only have the words Account or New in
    them. They are a part of a longer string where those words are just the
    beginning of that string. For example: AccountSalary, or NewMachine.
    What I want to do is delete the rows of associated with any cell in
    column E that do not have the words Account or New as a part of the
    value in the cell. Thank you for you help.

    Myles wrote:
    > sub n()
    > dim c as range
    > set rng = Range("e1",Cells(rows.count,"e").end(xlUp))
    > for each c in rng
    > if c.value="Account" or c.value="New" then
    > c.entirerow.delete
    > end if
    > next
    > end sub
    >
    >
    > hth
    > myles
    >
    >
    > --
    > Myles
    > ------------------------------------------------------------------------
    > Myles's Profile: http://www.excelforum.com/member.php...o&userid=28746
    > View this thread: http://www.excelforum.com/showthread...hreadid=574183



  4. #4
    Registered User
    Join Date
    08-14-2006
    Posts
    29
    Sub sWords()
    Range("E1").Select

    Do While Len(ActiveCell.Value) <> 0
    str1 = InStr(1, ActiveCell.Value, "New")
    str2 = InStr(1, ActiveCell.Value, "Account")
    If str1 >= 1 Or str2 >= 1 Then
    ActiveCell.Offset(1, 0).Select
    Else
    Selection.Delete Shift:=xlUp
    End If
    Loop

    End Sub

    That should do it.

    Cheers
    Joe

+ 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