+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    02-20-2009
    Location
    La, CA
    MS-Off Ver
    Excel 2003
    Posts
    70

    problem deleting entire row based on a condition

    Hey everyone

    I have a problem deleting rows based on a condition, i didn't know how to use offset method.

    i'm using a table like this one :

    A B C
    1 Main design1 FFR0
    2 Extra design2 FFR0
    3 Main design3 FFR0
    4 Extra design4 FFR0
    .
    .
    n Main designn FFR0


    I want to delete entire row if "FFR0" in column C exists in a row beginning by "EXTRA" (column A)

    thanks in advance for your help
    regards
    Last edited by mehdoush; 05-18-2009 at 10:26 AM.

  2. #2
    Forum Guru sweep's Avatar
    Join Date
    04-03-2007
    Location
    Location: Location:
    MS-Off Ver
    XL2003 / 2007
    Posts
    2,448

    Re: problem deleting entire row based on a condition

    Hi,

    Code:
    Sub Macro1()
    Dim rcell As Range
    For Each rcell In Range("A:A")
    If Left(rcell.Value, 5) = "Extra" And Left(rcell.Offset(0, 2).Value, 4) = "FFR0" Then rcell.EntireRow.Delete
    Next rcell
    End Sub
    Sarcasm - because beating the **** out of someone is illegal.

  3. #3
    Registered User
    Join Date
    02-20-2009
    Location
    La, CA
    MS-Off Ver
    Excel 2003
    Posts
    70

    Re: problem deleting entire row based on a condition

    thanks sweep, i'll try it

  4. #4
    Registered User
    Join Date
    02-20-2009
    Location
    La, CA
    MS-Off Ver
    Excel 2003
    Posts
    70

    Re: problem deleting entire row based on a condition

    well it didn't work properly, i think it's because the range (range("a:a"))

    i tried to use "intersect" method to define the range, but it didn't work either

    any help plz ??

  5. #5
    Forum Guru sweep's Avatar
    Join Date
    04-03-2007
    Location
    Location: Location:
    MS-Off Ver
    XL2003 / 2007
    Posts
    2,448

    Re: problem deleting entire row based on a condition

    It was fine with the example data you posted.

    How did it not work?

  6. #6
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,228

    Re: problem deleting entire row based on a condition

    There's no need to evaluate the entire column A, and if you don't start at the bottom and work UP, you'll end up skipping rows. My suggestion:
    Code:
    Sub DeleteRows()
    Dim i As Long, LastRow As Long
    LastRow = Range("A" & Rows.Count).End(xlUp).Row
    
        For i = LastRow To 1 Step -1
            If LCase(Cells(i, "A").Value) Like "extra*" And _
                UCase(Cells(i, "C").Value) Like "FFR0*" Then _
                    Rows(i).EntireRow.Delete
        Next i
    End Sub
    Last edited by JBeaucaire; 05-13-2009 at 11:44 AM. Reason: Added the wildcard onto FFR0*
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  7. #7
    Registered User
    Join Date
    02-20-2009
    Location
    La, CA
    MS-Off Ver
    Excel 2003
    Posts
    70

    Re: problem deleting entire row based on a condition

    thank you so much, it works properly

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.2.0