MACRO which deletes a row, when it finds a specific number

S

Spiros

Hi,

I want to create a macro which find one specific number in the column B and
delete the row.
For example: There is the number 60 in the cell B15 by accident. The macro
will delete the row No 15.

Thanks in advance,
Spiros
 
P

Pete_UK

You could apply autofilter to column B, select 60 from the drop-down,
highlight the visible rows and Edit | Delete Row. Then select All from
the drop-down.

Hope this helps.

Pete
 
S

Spiros

Guys thank you for your suggestions.
I find this macro end it works.

Sub testme02()

Dim myRng As Range
Dim FoundCell As Range
Dim wks As Worksheet
Dim myStrings As Variant
Dim iCtr As Long

myStrings = Array("60") 'add more strings if you need

Set wks = ActiveSheet

With wks
Set myRng = .Range("b2:b" & .Rows.Count)
End With

For iCtr = LBound(myStrings) To UBound(myStrings)
Do
With myRng
Set FoundCell = .Cells.Find(what:=myStrings(iCtr), _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
lookat:=xlWhole, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)

If FoundCell Is Nothing Then
Exit Do
Else
FoundCell.EntireRow.Delete
End If
End With
Loop
Next iCtr
End Sub

Ο χÏήστης "Don Guillett" έγγÏαψε:
 

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