![]() |
Find & Delete
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: , , and . Any suggestions? Thanks, Mike. |
Find & Delete
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 -- Regards Frank Kabel Frankfurt, Germany Mike wrote: 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: , , and . Any suggestions? Thanks, Mike. |
Find & Delete
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 -- Regards, Tom Ogilvy "Mike" wrote in message ... 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: , , and . Any suggestions? Thanks, Mike. |
All times are GMT +1. The time now is 02:59 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com