Macro to find row and delete it

  • Thread starter Thread starter Piet Lauwen
  • Start date Start date
P

Piet Lauwen

Hi group,

I am working on this macro now for some days now but with no succes....

From Worksheet3 I ask input for an "Item" (f.i. serialnumber) with an input
box.
The "item" has to be found in the first collumn of a database in
Worksheet2.
When the "Item" is found the complete row where it is foud should be
deleted.

What approach should I take?

Thanks in Adavance,

Piet Lauwen

e-Mail: piet.lauwen@(removethis)home.nl
 
Dim rng as Range
Dim sItem as String
Dim res as Variant
do until len(Trim(sItem)) > 0
sItem = InputBox("Input Serial Number:")
Loop
With Worksheets("Sheet2")
set rng = .Range( _
.Cells(2,1),.Cells(rows.count,1).end(xlup))
End With
res = Application.Match(sItem, rng, 0)
if not iserror(res) then
rng(res).EntireRow.Delete
End if


if the serial number and values in Column A of sheet2 will be numeric
change

res = Application.Match(clng(sItem), rng, 0 )
 
Back
Top