Find & Delete

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Hi. I am trying to create a macro that will search a
spreadsheet for a certain string. For each cell that
contains this string, I would like to delete the contents
of the cell.

For instance, if the string were "msn.com", I would
expect the following text strings to be found and the
cell values set to be null: (e-mail address removed),
(e-mail address removed), and (e-mail address removed).

Any suggestions?

Thanks,
Mike.
 
Hi Mike
try the following:

Sub find_delete()
Dim rng As Range
Dim cell As Range
Application.ScreenUpdating = False
Set rng = Selection
For Each cell In rng
If InStr(cell.Value, "msn.com") Then
cell.ClearContents
End If
Next
Application.ScreenUpdating = True
End Sub


Deletes all cells with the string 'msn.com' within your selection
 
Sub tester3()
Dim rng As Range
Set rng = Cells.Find(What:="msn.com", _
LookIn:=xlValues, LookAt:=xlPart)
If Not rng Is Nothing Then
Do
rng.ClearContents
Set rng = Cells.FindNext(rng)
Loop While Not rng Is Nothing
End If

End Sub
 
Back
Top