delete rows

J

jcc31

Hi,
Here is my attacthment. Can someone show me how if there is a way that
I can do the following macro?
Select every row that DOES NOT have either 12347 or 12360 in column G
and delete those rows?
My orginal total is 14. When the macro is done I should have 7.


+-------------------------------------------------------------------+
|Filename: test.zip |
|Download: http://www.excelforum.com/attachment.php?postid=4099 |
+-------------------------------------------------------------------+
 
C

Chip Pearson

I didn't open your attachment (I don't know whether it contains
nefarious code), but the follow code should do essentially what
you want.


Dim RowNdx As Long
Dim LastRow As Long

LastRow = Cells(Rows.Count, "G").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If Not (Cells(RowNdx, "G").Value = 12347 Or _
Cells(RowNdx, "G").Value = 12360) Then
Rows(RowNdx).Delete
End If
Next RowNdx



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"jcc31" <[email protected]>
wrote in message
news:[email protected]...
 
J

jcc31

That worked perfect. OH just one small addition. I would like the keep
the first row. The header row that has the name zip.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top