+ Reply to Thread
Results 1 to 9 of 9

Find a specific string in a cell

  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
    loren.pottinger
    Guest

    Re: Find a specific string in a cell

    I appologize but I forgot to mention that I am attemting to do this
    using VBA. Also, I have been attempting to use the find method, but I
    have been receiving several errors.

    loren.pottinger wrote:
    > 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



  3. #3
    loren.pottinger
    Guest

    Re: Find a specific string in a cell

    I appologize but I forgot to mention that I am attemting to do this
    using VBA. Also, I have been attempting to use the find method, but I
    have been receiving several errors.

    loren.pottinger wrote:
    > 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



  4. #4
    Dave Peterson
    Guest

    Re: Find a specific string in a cell

    Maybe something like:

    Option Explicit
    Sub testme()

    Dim iCtr As Long
    Dim myWords As Variant
    Dim iRow As Long
    Dim FirstRow As Long
    Dim LastRow As Long
    Dim KeepIt As Boolean

    myWords = Array("New", "Account")

    With Worksheets("sheet1")
    FirstRow = 1
    LastRow = .Cells(.Rows.Count, "E").End(xlUp).Row

    For iRow = LastRow To FirstRow Step -1
    KeepIt = False
    For iCtr = LBound(myWords) To UBound(myWords)
    If InStr(1, .Cells(iRow, "E").Value, myWords(iCtr), _
    vbTextCompare) > 0 Then
    KeepIt = True
    Exit For
    End If
    Next iCtr
    If KeepIt = True Then
    'do nothing
    Else
    .Rows(iRow).Delete
    End If
    Next iRow
    End With

    End Sub

    Test it against a copy--just to be safe.

    "loren.pottinger" wrote:
    >
    > 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


    --

    Dave Peterson

  5. #5
    loren.pottinger
    Guest

    Re: Find a specific string in a cell

    Hey Dave. Thanks for the reply. I attempted that but it didn't
    exactly work. It deleted everything.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.

    Dave Peterson wrote:
    > Maybe something like:
    >
    > Option Explicit
    > Sub testme()
    >
    > Dim iCtr As Long
    > Dim myWords As Variant
    > Dim iRow As Long
    > Dim FirstRow As Long
    > Dim LastRow As Long
    > Dim KeepIt As Boolean
    >
    > myWords = Array("New", "Account")
    >
    > With Worksheets("sheet1")
    > FirstRow = 1
    > LastRow = .Cells(.Rows.Count, "E").End(xlUp).Row
    >
    > For iRow = LastRow To FirstRow Step -1
    > KeepIt = False
    > For iCtr = LBound(myWords) To UBound(myWords)
    > If InStr(1, .Cells(iRow, "E").Value, myWords(iCtr), _
    > vbTextCompare) > 0 Then
    > KeepIt = True
    > Exit For
    > End If
    > Next iCtr
    > If KeepIt = True Then
    > 'do nothing
    > Else
    > .Rows(iRow).Delete
    > End If
    > Next iRow
    > End With
    >
    > End Sub
    >
    > Test it against a copy--just to be safe.
    >
    > "loren.pottinger" wrote:
    > >
    > > 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

    >
    > --
    >
    > Dave Peterson



  6. #6
    Dave Peterson
    Guest

    Re: Find a specific string in a cell

    The code actually looks at the whole cell and if account or new is anywhere in
    that cell, that row is kept.

    Your data is in column E, right?

    And in Sheet1??

    If you changed the code, maybe you should post your version.

    "loren.pottinger" wrote:
    >
    > Hey Dave. Thanks for the reply. I attempted that but it didn't
    > exactly work. It deleted everything.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.
    >
    > Dave Peterson wrote:
    > > Maybe something like:
    > >
    > > Option Explicit
    > > Sub testme()
    > >
    > > Dim iCtr As Long
    > > Dim myWords As Variant
    > > Dim iRow As Long
    > > Dim FirstRow As Long
    > > Dim LastRow As Long
    > > Dim KeepIt As Boolean
    > >
    > > myWords = Array("New", "Account")
    > >
    > > With Worksheets("sheet1")
    > > FirstRow = 1
    > > LastRow = .Cells(.Rows.Count, "E").End(xlUp).Row
    > >
    > > For iRow = LastRow To FirstRow Step -1
    > > KeepIt = False
    > > For iCtr = LBound(myWords) To UBound(myWords)
    > > If InStr(1, .Cells(iRow, "E").Value, myWords(iCtr), _
    > > vbTextCompare) > 0 Then
    > > KeepIt = True
    > > Exit For
    > > End If
    > > Next iCtr
    > > If KeepIt = True Then
    > > 'do nothing
    > > Else
    > > .Rows(iRow).Delete
    > > End If
    > > Next iRow
    > > End With
    > >
    > > End Sub
    > >
    > > Test it against a copy--just to be safe.
    > >
    > > "loren.pottinger" wrote:
    > > >
    > > > 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

    > >
    > > --
    > >
    > > Dave Peterson


    --

    Dave Peterson

  7. #7
    Dave Peterson
    Guest

    Re: Find a specific string in a cell

    I see you have another thread elsewhere.

    I'll drop out.

    Dave Peterson wrote:
    >
    > The code actually looks at the whole cell and if account or new is anywhere in
    > that cell, that row is kept.
    >
    > Your data is in column E, right?
    >
    > And in Sheet1??
    >
    > If you changed the code, maybe you should post your version.
    >
    > "loren.pottinger" wrote:
    > >
    > > Hey Dave. Thanks for the reply. I attempted that but it didn't
    > > exactly work. It deleted everything.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.
    > >
    > > Dave Peterson wrote:
    > > > Maybe something like:
    > > >
    > > > Option Explicit
    > > > Sub testme()
    > > >
    > > > Dim iCtr As Long
    > > > Dim myWords As Variant
    > > > Dim iRow As Long
    > > > Dim FirstRow As Long
    > > > Dim LastRow As Long
    > > > Dim KeepIt As Boolean
    > > >
    > > > myWords = Array("New", "Account")
    > > >
    > > > With Worksheets("sheet1")
    > > > FirstRow = 1
    > > > LastRow = .Cells(.Rows.Count, "E").End(xlUp).Row
    > > >
    > > > For iRow = LastRow To FirstRow Step -1
    > > > KeepIt = False
    > > > For iCtr = LBound(myWords) To UBound(myWords)
    > > > If InStr(1, .Cells(iRow, "E").Value, myWords(iCtr), _
    > > > vbTextCompare) > 0 Then
    > > > KeepIt = True
    > > > Exit For
    > > > End If
    > > > Next iCtr
    > > > If KeepIt = True Then
    > > > 'do nothing
    > > > Else
    > > > .Rows(iRow).Delete
    > > > End If
    > > > Next iRow
    > > > End With
    > > >
    > > > End Sub
    > > >
    > > > Test it against a copy--just to be safe.
    > > >
    > > > "loren.pottinger" wrote:
    > > > >
    > > > > 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
    > > >
    > > > --
    > > >
    > > > Dave Peterson

    >
    > --
    >
    > Dave Peterson


    --

    Dave Peterson

  8. #8
    Don Guillett
    Guest

    Re: Find a specific string in a cell

    suggest looking in vba help for FIND and then FINDNEXT

    --
    Don Guillett
    SalesAid Software
    dguillett1@austin.rr.com
    "loren.pottinger" <loren.pottinger@gmail.com> wrote in message
    news:1156254731.496431.192850@p79g2000cwp.googlegroups.com...
    >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
    >




  9. #9
    loren.pottinger
    Guest

    Re: Find a specific string in a cell

    Thanks Don and Dave. I was able to solve it with some help from
    elsewhere.
    Dave Peterson wrote:
    > I see you have another thread elsewhere.
    >
    > I'll drop out.
    >
    > Dave Peterson wrote:
    > >
    > > The code actually looks at the whole cell and if account or new is anywhere in
    > > that cell, that row is kept.
    > >
    > > Your data is in column E, right?
    > >
    > > And in Sheet1??
    > >
    > > If you changed the code, maybe you should post your version.
    > >
    > > "loren.pottinger" wrote:
    > > >
    > > > Hey Dave. Thanks for the reply. I attempted that but it didn't
    > > > exactly work. It deleted everything.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.
    > > >
    > > > Dave Peterson wrote:
    > > > > Maybe something like:
    > > > >
    > > > > Option Explicit
    > > > > Sub testme()
    > > > >
    > > > > Dim iCtr As Long
    > > > > Dim myWords As Variant
    > > > > Dim iRow As Long
    > > > > Dim FirstRow As Long
    > > > > Dim LastRow As Long
    > > > > Dim KeepIt As Boolean
    > > > >
    > > > > myWords = Array("New", "Account")
    > > > >
    > > > > With Worksheets("sheet1")
    > > > > FirstRow = 1
    > > > > LastRow = .Cells(.Rows.Count, "E").End(xlUp).Row
    > > > >
    > > > > For iRow = LastRow To FirstRow Step -1
    > > > > KeepIt = False
    > > > > For iCtr = LBound(myWords) To UBound(myWords)
    > > > > If InStr(1, .Cells(iRow, "E").Value, myWords(iCtr), _
    > > > > vbTextCompare) > 0 Then
    > > > > KeepIt = True
    > > > > Exit For
    > > > > End If
    > > > > Next iCtr
    > > > > If KeepIt = True Then
    > > > > 'do nothing
    > > > > Else
    > > > > .Rows(iRow).Delete
    > > > > End If
    > > > > Next iRow
    > > > > End With
    > > > >
    > > > > End Sub
    > > > >
    > > > > Test it against a copy--just to be safe.
    > > > >
    > > > > "loren.pottinger" wrote:
    > > > > >
    > > > > > 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
    > > > >
    > > > > --
    > > > >
    > > > > Dave Peterson

    > >
    > > --
    > >
    > > Dave Peterson

    >
    > --
    >
    > Dave Peterson



+ 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