+ Reply to Thread
Results 1 to 6 of 6

Creating a macro that will delete row based on non matching cell to previous line

  1. #1
    Registered User
    Join Date
    03-21-2012
    Location
    Kansas City, Mo
    MS-Off Ver
    Excel 2007
    Posts
    17

    Creating a macro that will delete row based on non matching cell to previous line

    I have attached a file of some sample data to assist in my question.

    Basically I would like a VBA macro that will keep the lines that are highlighted yellow based upon the fact that G6 matches the value of 672 and then it has a negative amount in I6 that is equal to H5*-1. If all of this criteria is true then keep the two matching rows. If not then delete all other rows that do not match this criteria.

    Is this possible? Thank you for your help!! I will leave good feedbackSample Date for VBA.xlsx

  2. #2
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Creating a macro that will delete row based on non matching cell to previous line

    Yes freidhofr.. this seems to be possible.

    One query here -> do you always want to match the column G values with 672? Is this number available anywhere in the spreadsheet?

    Regards,
    DILIPandey

    <click on below 'star' if this helps>
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), [email protected]

  3. #3
    Registered User
    Join Date
    03-21-2012
    Location
    Kansas City, Mo
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Creating a macro that will delete row based on non matching cell to previous line

    Yes always match column G values with 672

  4. #4
    Registered User
    Join Date
    03-21-2012
    Location
    Kansas City, Mo
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Creating a macro that will delete row based on non matching cell to previous line

    This is what i have so far but it keeps deleting everything

    Sub test()

    Dim r As Long, LR As Long

    LR = Range("G" & Rows.Count).End(xlUp).Row

    For r = LR To 2 Step -1
    With Range("M" & r)
    .Formula = "=IF(RC[-6]=""672"",IF(R[-2]C[-4]=(R[-1]C[-5]*-1),""Yes"",""No""),""No"")"
    .Value = .Value
    If .Value = "No" Then Rows(r).EntireRow.Delete
    End With
    Next

    End Sub

  5. #5
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Creating a macro that will delete row based on non matching cell to previous line

    Hi friend...

    See the attachment and where I have given a button in circle shape. Let me know if you need any further change(s) after your testing. Thanks.

    Regards,
    DILIPandey

    <click on below 'star' if this helps>
    Attached Files Attached Files

  6. #6
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Creating a macro that will delete row based on non matching cell to previous line

    Please don't start several threads with the same problem. Pick either this thread or the other thread and ask one of the moderators to lock the other.
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

+ 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