Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro Writing Help?

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Macro Writing Help?

Richard,

Try something like

Dim RowNdx As Long
Dim EndRow As Long
Dim StartRow As Long
Dim ColNdx As Long
EndRow = 100 ' << CHANGE
StartRow = 10 ' << CHANGE
ColNdx = 3 '<< CHANGE
For RowNdx = EndRow To StartRow Step -1
If Cells(RowNdx,ColNdx).Value = "X" Then
Rows(RowNdx).Delete
End If
Next RowNdx


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
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.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro writing dannyboy8 Excel Worksheet Functions 1 April 22nd 09 02:51 AM
Writing a macro RB[_2_] Excel Worksheet Functions 0 January 14th 08 05:40 PM
Writing Excel Macro McHarrisco Excel Worksheet Functions 1 November 30th 05 09:28 PM
writing macro CN New Users to Excel 2 August 2nd 05 06:16 PM
Writing Macro Tammy Klein Excel Programming 1 October 3rd 03 09:13 PM


All times are GMT +1. The time now is 02:35 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"