+ Reply to Thread
Results 1 to 7 of 7

How to delete rows that do not contain one of two texts. Excel VBA

  1. #1
    Registered User
    Join Date
    06-06-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    3

    How to delete rows that do not contain one of two texts. Excel VBA

    Hi,

    I am working with a set of data in 2007 excel where I am only looking for the rows in which the cell in column A contains somewhere in the text either "reports" or "insights/" (quotes are not part of it). I am looking to have all other cells deleted. Right now I have this code for excel vba:


    Sub RemoveRows()
    Dim LR As Long, i As Long
    LR = Range("A" & Rows.Count).End(xlUp).Row
    For i = LR To 2 Step -1
    If Not Range("A" & i).Value Like "*reports*" Then Rows(i).Delete
    Next i
    End Sub


    My problem is that it currently only works for reports, and deletes everything else, but I would like it to also keep insights/ as well. If anyone can modify this code, or offer a completely different code that will get the job done I would really apperiacte it.
    Last edited by Illini; 06-06-2012 at 02:45 PM.

  2. #2
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: How to delete rows that do not contain one of two texts. Excel VBA

    Please Login or Register  to view this content.
    That should do it.
    .?*??)
    `?.???.?*??)?.?*?)
    (?.?? (?.?
    Pichingualas <---
    ??????????????????????????

    Wrap your code with CODE TAGS.
    Thank those who helped you, Don't forget to add to their REPUTATION!!! (click on the star below their post).
    Please mark your threads as [SOLVED] when they are (Thread Tools->Mark thread as Solved).

  3. #3
    Registered User
    Join Date
    06-06-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: How to delete rows that do not contain one of two texts. Excel VBA

    thanks, but it did not work, though I ended up getting it with something similar

    Sub RemoveRows()
    Dim LR As Long, i As Long
    LR = Range("A" & Rows.Count).End(xlUp).Row
    For i = LR To 2 Step -1
    If Not (Range("A" & i).Value Like "*reports*" Or Range("A" & i).Value Like "*insights/*") Then Rows(i).Delete
    Next i
    End Sub

  4. #4
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: How to delete rows that do not contain one of two texts. Excel VBA

    hmm i thought it would

  5. #5
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: How to delete rows that do not contain one of two texts. Excel VBA

    I mean, Not(A Or B) = Not(A) And Not(B), so both choices should work.

  6. #6
    Registered User
    Join Date
    06-06-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: How to delete rows that do not contain one of two texts. Excel VBA

    Acutally your right, they do both work.

    Thanks by the way!

  7. #7
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: How to delete rows that do not contain one of two texts. Excel VBA

    No problem

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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