Solved

Deleting select rows in Excel

Posted on 2014-01-17
3
231 Views
Last Modified: 2014-01-19
I have a spreadsheet , that I have attached.  There are thousands of rows that we want to delete automatically if a certain condition is true.

The rows represent unique records that are kind of nested. We want to delete the rows associAted with the  "ABC STAR" as an example:

10017410203395 REBECCA BUFFINGTON FOR DCB 10/31/2013 US
PNC Star
IJR ISHARES CORE S&P SMALL-CAP E 32.000% 30.680% 1.320%
CASH 3.000% 4.010% 1.010%

if we find PNC STAR, we want to delete the row above "10017410203395 ...." and delete the rows following PNC STAR until we hit the next occurance of 10017...." .  We want to repeat this until all rows are deleted that we want. in the example spreadsheet you will see :  We do not want those rows to be deleted.  Is there anyway to write a macro or something to do this?  This is example data and does not contain and private or confidentail information.

I have tried using the statement in Column C , but its marking everything as delete. However if you look at row 159 -161 those should be marked as Keep, as they dont contain PNC Star.
Test-Drift.xlsx
0
Comment
Question by:seamus9909
  • 2
3 Comments
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39790524
Hi,

Is this what you want ?

I used this code

Sub Macro()
Application.ScreenUpdating = False
LastNameRw = Range("A" & Cells.Rows.Count).End(xlUp).Row
RwIdx = Range("A" & Cells.Rows.Count).End(xlUp).Row

Do While RwIdx > 1
    
    Debug.Print Range("A" & RwIdx)
    If Range("A" & RwIdx) = "PNC Star" Then
        Range("A" & RwIdx - 1 & ":A" & LastNameRw).EntireRow.Delete
    End If
    If Range("A" & RwIdx) Like "[0-9][0-9][0-9][0-9][0-9][0-9]*" Then
        LastNameRw = RwIdx - 1
    End If
    RwIdx = RwIdx - 1
Loop
Application.ScreenUpdating = False
End Sub

Open in new window

Regards
Test-DriftV1.xlsm
0
 

Author Comment

by:seamus9909
ID: 39790693
so you used the sheet I provided, and you run the macro and it creates a new sheet called results?
0
 
LVL 50

Expert Comment

by:Rgonzo1971
ID: 39792084
Hi,

No. I copied the sheet and run the macro on the copied sheet

Regards
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question