+ Reply to Thread
Results 1 to 5 of 5

Delete row that meets conditions and the one below

  1. #1
    Registered User
    Join Date
    10-22-2009
    Location
    Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    11

    Delete row that meets conditions and the one below

    Hi,

    I've got a question,

    I've got a spreadsheet of approximately 5000-10000 rows long,
    I've got a sort macro running but now i would like it to do the following:

    In Column C are the entries: COR, NEW or REP. I would like create a macro
    that deletes the rows with COR in column C, AND the row below it.

    How can i do this? Tis is what i've got sofar:

    ' Select sheet Pivot1
    Sheets("Pivot1").Select
    ' Turn off screen updating to speed up macro
    Application.ScreenUpdating = False
    ' Sort data
    ActiveWorkbook.Worksheets("Pivot1").AutoFilter.Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Pivot1").AutoFilter.Sort.SortFields.Add Key:=Range _
    ("D2:D5607"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
    xlSortNormal
    ActiveWorkbook.Worksheets("Pivot1").AutoFilter.Sort.SortFields.Add Key:=Range _
    ("C2:C5607"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
    xlSortNormal
    ActiveWorkbook.Worksheets("Pivot1").AutoFilter.Sort.SortFields.Add Key:=Range _
    ("AA2:AA5607"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
    xlSortNormal
    ActiveWorkbook.Worksheets("Pivot1").AutoFilter.Sort.SortFields.Add Key:=Range _
    ("V2:V5607"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
    xlSortNormal
    ActiveWorkbook.Worksheets("Pivot1").AutoFilter.Sort.SortFields.Add Key:=Range _
    ("H2:H5607"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
    xlSortNormal
    With ActiveWorkbook.Worksheets("Pivot1").AutoFilter.Sort
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply

    Sheets("Worksheet").Select
    End With
    End Sub
    I also would like to make sure that in the sorting bit, it doesen't stop at row 5607 but automaticly select the entire column (number of rows never the same)
    Last edited by Turbobiker; 10-23-2009 at 08:45 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: Delete row that meets conditions and the one below

    hello,

    please try this for the deletion of the rows
    Please Login or Register  to view this content.
    I tryed to clean up the sort & add the last row, I have not tested this though try
    Please Login or Register  to view this content.
    hope it helps
    Last edited by D_Rennie; 10-23-2009 at 09:11 AM. Reason: fix end with

  3. #3
    Registered User
    Join Date
    10-22-2009
    Location
    Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Delete row that meets conditions and the one below

    It runs the macro, but the rows with COR in Column (and the row below)
    arren't deleted.

    What can be wrong? The data is obtained from a Pivot Table, and the values are
    copied (with paste special) to a new worksheet...

  4. #4
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: Delete row that meets conditions and the one below

    Could you please post a sample workbook.

    Thank you.

  5. #5
    Registered User
    Join Date
    10-22-2009
    Location
    Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Delete row that meets conditions and the one below

    Got it sorted :D
    Thought it over during the weekend, and got it fixed now.

    It's a bit cumbersome, but it works good. (crosschecked it 3 times)
    It's now this:

    Columns("C:C").Select
    Selection.Replace What:="COR", Replacement:="", LookAt:=xlWhole
    Selection.SpecialCells(xlCellTypeBlanks).Select
    Selection.EntireRow.Delete
    Selection.EntireRow.Delete
    Range("B1").Select

+ 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