Solved

Deleting select rows in Excel

Posted on 2014-01-17
3
221 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 49

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 49

Expert Comment

by:Rgonzo1971
ID: 39792084
Hi,

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

Regards
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

813 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

13 Experts available now in Live!

Get 1:1 Help Now