Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how do i delete rows when cells meet certain criteria?


I want to delete rows 3 - 5 if the value in column b (of any of the
respective rows) is zero. Below is the code that I am using but it is
not working. It is leaving one of the "zero rows" in place (it is only
deleting two of the rows when all three should be deleted). Any help
would be greatly appreciated.

Dim myRng As Range
Dim zerocell As Range
Set myRng = Range("b3:b5")
For Each zerocell In myRng
If zerocell.Text = "0" Then
zerocell.EntireRow.Delete
End If
Next

I've also tried this (and I have the same problem):

Dim myRng As Range
Dim zerocell As Range
Set myRng = Range("b3:b5")
For Each zerocell In myRng
If zerocell = 0 Then
zerocell.EntireRow.Delete
End If
Next
_________________
Thanks, TB


--
Tbal
------------------------------------------------------------------------
Tbal's Profile: http://www.excelforum.com/member.php...o&userid=25317
View this thread: http://www.excelforum.com/showthread...hreadid=395819

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default how do i delete rows when cells meet certain criteria?

if application.countif(Range("B3:B5"),0) 0 then
rows(3).Resize(3).Delete
End if

--
Regards,
Tom Ogilvy

"Tbal" wrote in message
...

I want to delete rows 3 - 5 if the value in column b (of any of the
respective rows) is zero. Below is the code that I am using but it is
not working. It is leaving one of the "zero rows" in place (it is only
deleting two of the rows when all three should be deleted). Any help
would be greatly appreciated.

Dim myRng As Range
Dim zerocell As Range
Set myRng = Range("b3:b5")
For Each zerocell In myRng
If zerocell.Text = "0" Then
zerocell.EntireRow.Delete
End If
Next

I've also tried this (and I have the same problem):

Dim myRng As Range
Dim zerocell As Range
Set myRng = Range("b3:b5")
For Each zerocell In myRng
If zerocell = 0 Then
zerocell.EntireRow.Delete
End If
Next
_________________
Thanks, TB


--
Tbal
------------------------------------------------------------------------
Tbal's Profile:

http://www.excelforum.com/member.php...o&userid=25317
View this thread: http://www.excelforum.com/showthread...hreadid=395819



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
Sum rows if muliple cells meet criteria but not others Amy Excel Discussion (Misc queries) 4 September 9th 09 03:56 PM
Formula/Macro to delete rows that do not meet criteria from a list? S Davis Excel Worksheet Functions 2 July 12th 06 07:42 PM
Delete data in cells that don't meet criteria SITCFanTN New Users to Excel 1 June 10th 06 09:03 PM
Delete Rows where cells does not meet criteria Danny Excel Worksheet Functions 1 September 12th 05 05:08 PM
Excel 2000 VBA - Delete Rows That Meet Criteria William Horton[_2_] Excel Programming 5 May 16th 05 07:51 PM


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