View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ron de Bruin Ron de Bruin is offline
external usenet poster
 
Posts: 11,123
Default Delete Rows except

If Left(Cells(RowNdx, "A"), 7) < "PCPB" Then

Change the 7 to 4


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"J.W. Aldridge" wrote in message oups.com...
I found the following code, but it doesnt work for me.
I need a code that will delete Rows A-H based on the data in column
A.

Example:

PCPB
PCPA
PCPC
PCPB
PCPD
PCPC
PCPB

I want to delete every row that doesn't start with PCPB.

This code doesnt work for me:

Dim LastRow As Long
Dim RowNdx As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
'<change column letter if desired
For RowNdx = LastRow To 1 Step -1
'<change '1' to ending row if desired
If Left(Cells(RowNdx, "A"), 7) < "PCPB" Then
Rows(RowNdx).Delete
End If
Next RowNdx