LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Junior Member
 
Posts: 6
Default Code to delete rows based on value

I have the following code that will delete all rows that DO NOT contain the value "11327" in column A. I need to expand this code to include roughly 40 values.

Here is what I have:

Sub delete_It()

Dim MyRange1 As Range
Dim MyRange As Range
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & lastrow)
For Each c In MyRange
If InStr(1, UCase(c.Value), "11327", 0) Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If

End Sub

Any help will be greatly appreciated.

Thanks,
DFB
 
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
Delete Rows based on # of rows (no variable?) DanaK Excel Programming 7 November 3rd 08 12:11 AM
Delete Rows based on value Sabosis Excel Worksheet Functions 4 October 28th 08 11:21 PM
Code for Excel 2007 to hide rows based on sum of several rows not ina range Joe Gardill Excel Programming 2 August 29th 08 03:53 PM
Code help, delete rows based on column criteria Stout Excel Discussion (Misc queries) 2 March 20th 07 01:17 PM
Delete rows based on value... Gordon[_2_] Excel Programming 3 September 15th 06 09:14 PM


All times are GMT +1. The time now is 11:39 PM.

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"