Need a Macro that will delete every odd row starting at row number

Need a Macro that will delete every odd row starting at row number

Post by dWZvX3BpbG » Wed, 26 Apr 2006 21:53:01


You should go to this site and download Andrew's Utilities ( one of the great
thing I have found here)
It has so many functions, that I still to this day have not tried all of them

http://www.yqcomputer.com/

Below is an exsample of one of the Sub's in that menu, which deletes rows
under certain conditions, like every 2nd row....or 5th row.
try it out first to see which rows it actually deletes on a copy of your
workbook first .



Sub DeleteRowsConditionally()
' Original VBA by Masaru Kaji aka Colo, Colo's Junk Room,
http://www.yqcomputer.com/
' Modified by Andrew Engwirda, Andrew's Excel Tips,
http://www.yqcomputer.com/
Dim myValue As String
Dim Proceed As Long
Dim cell As Range
Dim rDelete As Range
On Error GoTo Terminate
myValue = InputBox("Enter your value.", "Delete Rows Conditionally")
If myValue = "" Then Exit Sub
Proceed = MsgBox("Push YES to delete all rows with '" & myValue & "'" &
vbCrLf & vbCrLf & _
"Push NO to delete all rows without '" & myValue & "'"
& vbCrLf & vbCrLf & _
"Push Cancel to exit" & vbCrLf & vbCrLf & _
"Note: Entire rows will be deleted where " & vbCrLf
& _
"matches are found in each selected column.",
vbYesNoCancel, "Delete Rows Conditionally")
Call SetCalcSetting
Select Case Proceed
Case vbYes
For Each cell In Selection
If cell.Value = myValue Then
If rDelete Is Nothing Then
Set rDelete = cell.EntireRow
Else
Set rDelete = Union(rDelete, cell.EntireRow)
End If
End If
Next
rDelete.Delete
Case vbNo
For Each cell In Selection
If cell.Value <> myValue Then
If rDelete Is Nothing Then
Set rDelete = cell.EntireRow
Else
Set rDelete = Union(rDelete, cell.EntireRow)
End If
End If
Next
rDelete.Delete
Case Else
End Select
Terminate:
Call SetCalcSetting("Restore")
End Sub
 
 
 

Need a Macro that will delete every odd row starting at row number

Post by Brandon Ho » Wed, 26 Apr 2006 22:53:26

The macro did not work for me came up with some errors and I will have to
check that website at a later time, my company has a web filter installed
and I cannot access his site.

Thanks and I will let you know if it ends up working.

 
 
 

Need a Macro that will delete every odd row starting at row number

Post by Bob Philli » Wed, 26 Apr 2006 23:25:56

Did you try my suggestion?

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)