Solved

Deleting select rows in Excel

Posted on 2014-01-17
3
203 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 48

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 48

Expert Comment

by:Rgonzo1971
ID: 39792084
Hi,

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

Regards
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

705 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now