PDA

View Full Version : Automatically remove unwanted rows based on a known value



xlsior
12-13-2007, 08:34 AM
Hi all,

Im not strong in excel, that why Im here. So:
I work every day with big amount of item numbers and lists in excel and I need some macro or code to automatically remove rows, containing unwanted text.

Example:

MEMORY DIMM 512MB PC3200 DDR
MEMORY DIMM 512MB PC6400 DDRII
MEMORY DRIVE FLASH USB2 2GB
MEMORY MINI SD 2GB W/ADAPTER
MEMORY SECURE DIGITAL 2GB
MEMORY DIMM 1GB PC6400 DDRII
MEMORY DRIVE FLASH USB2 1GB
MEMORY DRIVE FLASH USB2 1GB

So I paste the text from my database, and want to automatically delete rows containing DIMM string. How can I do it?

p.s. is there also a way to leave only the rows I want?

Bob Phillips
12-13-2007, 08:57 AM
Public Sub ProcessData()
Const TEST_COLUMN As String = "A" '<=== change to suit
Dim i As Long
Dim iLastRow As Long

With ActiveSheet

iLastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = iLastRow To 1 Step -1
If .Cells(i, "A").Value Like "*DIMM*" Then
.Rows(i).Delete
End If
Next i

End With

End Sub

blackie42
12-13-2007, 08:58 AM
Assuming the word DIMM is in column B

Sub delrows()
Dim found As Range

Application.ScreenUpdating = False
Set found = Range("B:B").Find(What:="DIMM")
Do Until found Is Nothing
found.EntireRow.Delete
Set found = Range("B:B").FindNext
Loop
End Sub