Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default macro to delete a row based on criteria

I have a document with 6 columns of data and an unspecified number of rows.
I would like a macro to delete any row that has both columns 5 and 6 equal to
0. I would then need every other row to move up or down so there are no blank
rows.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default macro to delete a row based on criteria

Untested but should work.

Sub delRws()
Dim lr As Long, i As Long
lr = ActiveSheet.Cells(Rows.Count, 5).End(xlUp).Row
For i = lr To 2 Step -1
With ActiveSheet
If .Cells(i, 5) = 0 And .Cells(i, 6) = 0 Then
.Cells(i, 1).EntireRow.Delete
End If
End With
Next
End Sub

"aileen" wrote:

I have a document with 6 columns of data and an unspecified number of rows.
I would like a macro to delete any row that has both columns 5 and 6 equal to
0. I would then need every other row to move up or down so there are no blank
rows.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default macro to delete a row based on criteria

Public Sub ProcessData()
Dim i As Long
Dim LastRow As Long

With ActiveSheet

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = LastRow To 1 Step -1

If .Cells(i, "E").Value = 0 And .Cells(i, "F").Value = 0 Then

.Rows(i).Delete
End If
Next i
End With

End Sub

--
__________________________________
HTH

Bob

"aileen" wrote in message
...
I have a document with 6 columns of data and an unspecified number of rows.
I would like a macro to delete any row that has both columns 5 and 6 equal
to
0. I would then need every other row to move up or down so there are no
blank
rows.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default macro to delete a row based on criteria

Both of those worked. Thanks so much.

"Bob Phillips" wrote:

Public Sub ProcessData()
Dim i As Long
Dim LastRow As Long

With ActiveSheet

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = LastRow To 1 Step -1

If .Cells(i, "E").Value = 0 And .Cells(i, "F").Value = 0 Then

.Rows(i).Delete
End If
Next i
End With

End Sub

--
__________________________________
HTH

Bob

"aileen" wrote in message
...
I have a document with 6 columns of data and an unspecified number of rows.
I would like a macro to delete any row that has both columns 5 and 6 equal
to
0. I would then need every other row to move up or down so there are no
blank
rows.




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
delete part of a row based on certain criteria mark lane Excel Worksheet Functions 3 September 14th 06 01:16 AM
Macro to delete row based on criteria (first few characters of string) [email protected] Excel Programming 5 May 15th 06 06:11 PM
Delete rows based on criteria Chris_t_2k5 Excel Discussion (Misc queries) 2 April 11th 06 01:52 PM
Delete rows based on certain criteria Coal Miner Excel Discussion (Misc queries) 2 March 3rd 06 05:56 PM
Cut and Paste macro based on criteria then delete empty rows samst Excel Programming 4 November 2nd 03 09:33 PM


All times are GMT +1. The time now is 09:01 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"