how to delete specific values in cells

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.
 
G

Gary''s Student

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
 

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