View Single Post
  #6   Report Post  
Ron Rosenfeld
 
Posts: n/a
Default

On Sat, 09 Apr 2005 14:07:18 GMT, Ian wrote:

Is it possible to clear the contents of a cell if if contains a certain
text strings, i.e. I want to clear all cells in a particular column that
contain the phrases "son of", "dau of" and "wife of".

Thanks in advance.


You could use a VBA macro:

=========================
Sub ClearSpecial()
Dim i As Long, Count As Long
Dim c As Range
Dim Phrases As Variant

Phrases = Array("son of", "dau of", "wife of")

For Each c In Selection
For i = 0 To UBound(Phrases)
If InStr(c.Text, Phrases(i)) 0 Then
c.Clear
Count = Count + 1
End If
Next i
Next c

MsgBox (Str(Count) & " cells cleared")

End Sub
============================

To enter the macro, <alt-F11 opens the VB Editor.
Ensure your project is highlighted in the project explorer window, then
Insert/Module and paste the above code into the window that opens.

To use the macro, select the range containing the cells you wish to
conditionally clear. Then <alt-F8 opens the Macro Dialog box. Select your
macro and run it.

Many variations are possible depending on your precise requirements.


--ron