View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Charles Maxson Charles Maxson is offline
external usenet poster
 
Posts: 24
Default Macro Writing Help?

Two versions:

The first one knows the column that you are expecting the X's to be in (in
the sample its column 2 or 'B'). The second doesn't. Both are case sensitive
by design.


Sub DeleteTheXRows1()

Dim rw As Range
Dim col As Range

Set col = Columns(2)

For Each rw In Intersect(col, ActiveSheet.UsedRange)
If rw = "X" Then
rw.EntireRow.Delete
End If

Next

End Sub



This version will delete ANY row that contains a ANY cell with a single,
capital X. It does not assume the X's are in any particular column.


Sub DeleteTheXRows2()

Dim rw As Range
Dim rngFound As Range

On Error Resume Next

For Each rw In ActiveSheet.UsedRange.Rows

Set rngFound = rw.Find(What:="X", LookIn:=xlValues, LookAt:=xlWhole,
MatchCase:=True)

If Not rngFound Is Nothing Then
rw.Delete
Set rngFound = Nothing
End If

Next

End Sub


--
Charles
www.officezealot.com


"Richard" wrote in message
...
Can anyone help me with writing a macro that will delete
any rows that contain an "X" in a cell of a particular
column? The "X" would be indicator that the row should be
deleted by the macro.

Thank you.