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 !!!!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,456
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,456

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,456
You're very welcome. Thanks for the kind words. :)
Glad it helped.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,573
Messages
5,832,571
Members
430,142
Latest member
ivonsurf123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top