+ Reply to Thread
Results 1 to 8 of 8

Delete Rows that contain matching cell contents in column to the contents in cell B1

  1. #1
    Registered User
    Join Date
    10-27-2010
    Location
    Salisbury, Maryland
    MS-Off Ver
    Excel 2010
    Posts
    41

    Delete Rows that contain matching cell contents in column to the contents in cell B1

    Hi,

    I've been struggling with this for a few days now and still can not come up with the fix. I have the code below that is supposed to look at the contents of cell B1 and then delete all rows in column B whose cell content matches the entry in cell B1. I'm sure this may be a simple fix for most, but I'm still a bit of a novice with working with this stuff.

    Basically, I have another macro that goes to the applicable worksheet and activates cell B1 first. The problem with this code is that it deletes the first row because it is also a match.

    Sub DeleteMatchingRows()
    Dim LR As Long, i As Long
    With Sheets("Tracker")
    LR = .Range("B" & Rows.Count).End(xlUp).Row
    For i = LR To 1 Step -1
    If .Range("B" & i).Value = ActiveCell.Value Then .Rows(i).Delete
    Next i
    End With
    End Sub


    Any help would be greatly appreciated.

    Thanks,

    Steve

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Delete Rows that contain matching cell contents in column to the contents in cell B1

    Try this little change
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    10-27-2010
    Location
    Salisbury, Maryland
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Delete Rows that contain matching cell contents in column to the contents in cell B1

    I just tried it, but it still deletes my first row where the match is identified.

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Delete Rows that contain matching cell contents in column to the contents in cell B1

    So you can attach your wb to see it and decide what's wrong..
    I just edited the the loop to row 2 only away from row 1
    you may don't have enough data in column B so you can add this line before the loop
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-27-2010
    Location
    Salisbury, Maryland
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Delete Rows that contain matching cell contents in column to the contents in cell B1

    Yasser,

    I tried your last suggestion and it worked perfectly. You make it look so easy. Thank you so much.

    What did you mean by "So you can attach your wb to see it and decide what's wrong.."? Are you saying I need to attach my workbook to the forum somewhere? Not sure how to do that.



    Thanks again,

    Steve

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Delete Rows that contain matching cell contents in column to the contents in cell B1

    You're welcom Steve ..
    Yes, WB is abbreviate to Workbook.
    As for attachment, When you post a reply click "Go Advanced" and you will find an icon of attachment then a window will be opened click Add Files and Browse for your file you want to attach and finally upload then OK

  7. #7
    Registered User
    Join Date
    10-27-2010
    Location
    Salisbury, Maryland
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Delete Rows that contain matching cell contents in column to the contents in cell B1

    Excellent. Thanks. How do I mark this one "Solved"?

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Delete Rows that contain matching cell contents in column to the contents in cell B1

    Hi
    From Thread Tools at the top of the thread .. you will find (Mark as solved)
    And if you found that someone helped you and you want to appreciate him you can click the star (Add Reputation ) to add some points to his reputation

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Split cell contents over multiple rows based on cell contents
    By naigy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-17-2011, 05:38 PM
  2. Delete Rows Based On Cell Contents
    By aapke in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-28-2007, 08:14 PM
  3. [SOLVED] How do I conditionally delete rows based on cell contents?
    By CLR in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 09-06-2005, 07:05 AM
  4. [SOLVED] How do I conditionally delete rows based on cell contents?
    By John Chan in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM
  5. [SOLVED] How do I conditionally delete rows based on cell contents?
    By John Chan in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 PM

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