Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Need a Macro that will delete every odd row starting at row number 1.

Thanks Bob this one works perfect for me.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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.



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
Numbering pages, starting at a particular number Jammings Excel Discussion (Misc queries) 4 September 18th 09 03:17 PM
counting starting with a number other than 1 norman mellow Excel Discussion (Misc queries) 1 December 30th 08 08:42 PM
Delete every 2nd column from fixed starting point Darin Kramer Excel Programming 3 April 18th 06 11:17 AM
Find Replace Number Starting with 0 Amir Excel Discussion (Misc queries) 0 November 10th 05 05:10 PM
How do you keep a 3-digit number starting with a "0" (ie. 058) Jason Excel Discussion (Misc queries) 4 December 5th 04 11:24 PM


All times are GMT +1. The time now is 11:47 AM.

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

About Us

"It's about Microsoft Excel"