Help me delete unwanted rows in a sheet

nsman

New Member
Joined
Jul 25, 2010
Messages
26
I use Excel 2003 version. I have a sheet that contains lot of daily work info.
I need to extract info regarding a specific work and create a new sheet.
In the sheet, column 'A' has different entries in different rows. All are alphanumeric entries. But some of the rows has specific letters (always same letters) in the 5th and 6th position. I need to keep these rows and delete rest of the rows.

I am looking for a macro to do this

It will be of real great help . I can cut short the working on these from approx. 1.5 hours to just seconds.

Thanks all. I know u'll rock !!!!
 

Some videos you may like

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,453
All of the values to be evaluated are in column A?
What is the string (your specific letters) you want to search for in each cell? (If you want this to be case sensitive, you'll want to be specific here, otherwise we can make it non-case sensitive.)

And (just to make sure I understand...) you want to delete all rows that do not contain your search string somewhere in column A?
 

nsman

New Member
Joined
Jul 25, 2010
Messages
26
Yes. All of the values to be evaluated are in column A always.
Specific cells will contain a string 'P' in the first place, followed by a 3 digit number, followed by 2 letters "PS" in the fifth and sixth place. The letters are always same .. ie.. "P" & "PS". The number differs.
It is all CAPS.
The other rows contain different types of alphanumeric data in column A. Even some date headings in some rows. If it is possible I like to retain date headings. But if not, it is not a big issue.
 

nsman

New Member
Joined
Jul 25, 2010
Messages
26
Yes. I want to DELETE rows that DO NOT confirm to the format explained.

:)
 

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,453

ADVERTISEMENT

Does this work for you or did I misunderstand something?
Code:
Sub Demo()
Dim Lr As Long, i As Range, dlt As Range
Lr = Cells(Rows.Count, "A").End(xlUp).Row
Application.ScreenUpdating = False
For Each i In Range("A2:A" & Lr)
  If Left(i, 1) <> "P" Or Mid(i, 5, 2) <> "PS" Then
    If dlt Is Nothing Then
      Set dlt = i
    Else
      Set dlt = Union(i, dlt)
    End If
  End If
Next i
If Not dlt Is Nothing Then dlt.EntireRow.Delete
Application.ScreenUpdating = True
End Sub
Hope it helps. (but I'm leaving now so I won't know until tomorrow...)
 

nsman

New Member
Joined
Jul 25, 2010
Messages
26
Hi HalfAce,

It is wonderful .. U R a magician .. didn't I tell u that u r gonna rock .. !!!

u helped saving at least 45 minutes of man hour every day !!!

Thanks a ton .. :) .. :) .. :)

Glad ...
 

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,453
You're very welcome. Thanks for the kind words. :)
Glad it helped.
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,564
Messages
5,512,086
Members
408,879
Latest member
dilipsny

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top