Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default Delete Rows except

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default Delete Rows except



......worked like a charm!

Thanx.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default Delete Rows except


one more thing....

If I wanted the macro to start at A2 (instead of A1)?
(row a1 has my headers)



Sub Apples()
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"), 4) < "PCPB" Then
Rows(RowNdx).Delete
End If
Next RowNdx

End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Delete Rows except

For RowNdx = LastRow To 1 Step -1

Change to

For RowNdx = LastRow To 2 Step -1



--

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


"J.W. Aldridge" wrote in message ups.com...

one more thing....

If I wanted the macro to start at A2 (instead of A1)?
(row a1 has my headers)



Sub Apples()
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"), 4) < "PCPB" Then
Rows(RowNdx).Delete
End If
Next RowNdx

End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Delete Rows except

For RowNdx = LastRow To 2 Step -1

This loop works from the bottom row, up. So LastRow To 2 will stop after
doing row 2.

Mike F

"J.W. Aldridge" wrote in message
ups.com...

one more thing....

If I wanted the macro to start at A2 (instead of A1)?
(row a1 has my headers)



Sub Apples()
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"), 4) < "PCPB" Then
Rows(RowNdx).Delete
End If
Next RowNdx

End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hpw do I delete multiple empty rows found between filled rows? Bill Excel Worksheet Functions 2 November 15th 09 07:12 PM
Cut filtered rows, paste into next empty row of new sheet, and delete cut rows Scott Excel Worksheet Functions 0 December 13th 06 01:25 AM
Delete rows with numeric values, leave rows with text GSpline Excel Programming 5 October 11th 05 12:44 AM
How to delete rows when List toolbar's "delete" isnt highlighted? Linda Excel Worksheet Functions 1 May 26th 05 08:39 PM
Delete every 3rd row, then delete rows 2-7, move info f/every 2nd row up one to the end and delete the row below Annette[_4_] Excel Programming 2 September 21st 04 02:40 PM


All times are GMT +1. The time now is 03:31 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"