![]() |
Need a Macro that will delete every odd row starting at row number 1.
I have looked online and only found a macro that would delete every even row.
I have a recurring job that requires me to delete every odd row. Could someone please help me with this. Thanks, Brandon |
Need a Macro that will delete every odd row starting at row number 1.
Sub Test()
Dim iLastRow As Long Dim i As Long iLastRow = Cells(Rows.Count, "A").End(xlUp).Row If Int(iLastRow / 2) * 2 = iLastRow Then iLastRow = iLastRow - 1 For i = iLastRow To 1 Step -1 Rows(i).Delete Next i End Sub -- HTH Bob Phillips (remove nothere from email address if mailing direct) "Brandon Horne" wrote in message . .. I have looked online and only found a macro that would delete every even row. I have a recurring job that requires me to delete every odd row. Could someone please help me with this. Thanks, Brandon |
Need a Macro that will delete every odd row starting at row number
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.andrewsexceltips.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.puremis.net/excel ' Modified by Andrew Engwirda, Andrew's Excel Tips, http://www.andrewsexceltips.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 "Brandon Horne" wrote: I have looked online and only found a macro that would delete every even row. I have a recurring job that requires me to delete every odd row. Could someone please help me with this. Thanks, Brandon |
Need a Macro that will delete every odd row starting at row number
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
Did you try my suggestion?
-- HTH Bob Phillips (remove nothere from email address if mailing direct) "Brandon Horne" wrote in message . .. 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 1.
Thanks Bob this one works perfect for me.
|
All times are GMT +1. The time now is 08:11 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com