+ Reply to Thread
Results 1 to 5 of 5

Problem with conditional delete rows

  1. #1
    Registered User
    Join Date
    09-10-2003
    Posts
    9

    Question Problem with conditional delete rows

    Good morning everyone.

    I am using the following code :

    Sub test2()


    Do
    If ActiveCell = "CRK" Or ActiveCell = "STC" Then
    ActiveCell.Offset(1, 0).Select
    Else: Selection.EntireRow.Delete

    End If

    Loop Until ActiveCell = "WPR"

    End Sub

    to check the contents of column "A" in a spreadsheet, (I've selected cell A2 in the required spreadsheet before running the code). It seems to be working, as it deletes the rows that contain CRK and STC, but also deletes the rows that have WPR as well. The data is copied from another excel spreadsheet that is exported data from Oracle and I am using Office 97.

    It's probably something really obvious to some, but I've been searching the forums all morning trying to adjust the code, but nothing seems to be working for me.

    Any help anyone can offer would be greatly appreciated.

    Thanks in advance, and have a great day all!

  2. #2
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    I'm confused. You state that this code is deleting the rows with "CRK" and "STC" in them? It should leave all of those, and delete any rows that do NOT contain these two.

    Also, it deletes "WPR"? That code should run once, and stop at the cell containing "WPR". Is this Do Loop actually looped more than once? Or ran just once?

  3. #3
    Registered User
    Join Date
    09-10-2003
    Posts
    9
    Jason,

    Thanks for your response,

    Yes this code is deleting rows containing CRK and STC, and after seeing your reply, and actually reading the code, I see that it shouldn't be. So now I'm confused on that as well.

    This is the only code in the workbook, and it continues to delete rows including ones with WPR.

    I found the original code here on the forums through a search the only thing I changed was the CRK, STC and WPR. Is there maybe some kind of formatting I should be doing before trying to do this?

  4. #4
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Yes, that is odd. I just copied and pasted the code into a new workbook, and added some initials in column A, and it worked just how it is supposed to work. Sorry, I'm not sure why it is not working on your PC. Maybe someone else can chime in.

    Quote Originally Posted by Candee
    Jason,

    Thanks for your response,

    Yes this code is deleting rows containing CRK and STC, and after seeing your reply, and actually reading the code, I see that it shouldn't be. So now I'm confused on that as well.

    This is the only code in the workbook, and it continues to delete rows including ones with WPR.

    I found the original code here on the forums through a search the only thing I changed was the CRK, STC and WPR. Is there maybe some kind of formatting I should be doing before trying to do this?

  5. #5
    Registered User
    Join Date
    09-10-2003
    Posts
    9
    Thanks Jason, I appreciate your trying.

+ 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