how to delete specific values in cells

  • Thread starter Thread starter Tiangui
  • Start date Start date
T

Tiangui

Hi,
I have a problem with excel 2007. I want to delete some columns which
include some words (like as @xxx.com.au). How to delete those colums
with macro?
Pls let me know. Thanks.
 
Consider:

Sub col_killer()
Dim r As Range, cel As Range
Dim s As String
s = "@xxx.com.au"
Set r = Nothing

For Each cel In ActiveSheet.UsedRange
If cel.Value = s Then
If r Is Nothing Then
Set r = cel
Else
Set r = Union(r, cel)
End If
End If
Next

If r Is Nothing Then
Else
r.EntireColumn.Delete
End If
End Sub
 
Back
Top