+ Reply to Thread
Results 1 to 5 of 5

How to delete entire row if a cell value contains a portion of another cell value

  1. #1
    Registered User
    Join Date
    11-12-2012
    Location
    Ann Arbor, MI
    MS-Off Ver
    Excel 2010
    Posts
    2

    How to delete entire row if a cell value contains a portion of another cell value

    I have a cell F2 that contains a value (lets say 6008) dictated by a combobox so it is different each time. I am using the following code:

    Application.ScreenUpdating = False
    For i = Range("D65000").End(xlUp).Row To 4 Step -1
    If Trim(Cells(i, 4)) <> Range("F2") Then Rows(i).Delete
    Next
    Application.ScreenUpdating = True

    I want all of the remaining rows to have 6008 somewhere in the D column.

    It is deleting the rows when D? is not equal to 6008, but I don't want it to delete rows when D? equals 6008A, x6008, etc. How do I acomplish matching part of the cell (wildcard?)?

    Thanks!!!
    Last edited by NSK-ENG; 06-14-2013 at 11:11 AM.

  2. #2
    Forum Contributor
    Join Date
    10-13-2012
    Location
    Southern California
    MS-Off Ver
    Excel 2007
    Posts
    403

    Re: How to delete entire row if a cell value contains a portion of another cell value

    How many other "etc.'s" do you have?

    If you just have a few, the answer is simple. Just expand your IF statement. For example, something like this might work for you:

    a$ = Trim(Cells(i, 4))
    b$ = Trim(Cells(i, 4)) & "A"
    c$ = "x" & Trim(Cells(i, 4))

    If a$ <> Range("F2") and b$ <> Range("F2") and c$ <> Range("F2") Then Rows(i).Delete

  3. #3
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: How to delete entire row if a cell value contains a portion of another cell value

    Try:

    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: How to delete entire row if a cell value contains a portion of another cell value

    alternative
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-12-2012
    Location
    Ann Arbor, MI
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: How to delete entire row if a cell value contains a portion of another cell value

    Perfect, thanks!!

+ 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