Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Delete a row based on more than one condtion

I am using the following code to delete a row in a spreadsheet based
on the value (zero) in that row:

Sub RemoveZero()
Dim RngColAB As Range
Dim c As Long
Application.ScreenUpdating = False
Set RngColAB = Range("AB2", Range("AB" & Rows.Count).End(xlUp))
For c = RngColAB.Count To 1 Step -1
RngColAB(c).Value = Application.Trim(RngColAB(c))
If RngColAB(c).Value = 0 Then _
RngColAB(c).EntireRow.Delete
Next c
Application.ScreenUpdating = True
End Sub

How can I modify it so that it looks to two columns where both rows
have to have a zero value so that the row can be deleted?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Delete a row based on more than one condtion

change the line:
If RngColAB(c).Value = 0 Then _
to
If RngColAB(c).Value = 0 And Application.Trim(RngColAB(c).Offset(0,
7).value) = 0 Then _
where the 7 is a value I've chosn at random representing 7 cells to the
right of your cell being tested for 0. A 1 would be one cell to the right, a
-1 would be one cell to the left etc. etc.
(not tested).
--
p45cal


"Opal" wrote:

I am using the following code to delete a row in a spreadsheet based
on the value (zero) in that row:

Sub RemoveZero()
Dim RngColAB As Range
Dim c As Long
Application.ScreenUpdating = False
Set RngColAB = Range("AB2", Range("AB" & Rows.Count).End(xlUp))
For c = RngColAB.Count To 1 Step -1
RngColAB(c).Value = Application.Trim(RngColAB(c))
If RngColAB(c).Value = 0 Then _
RngColAB(c).EntireRow.Delete
Next c
Application.ScreenUpdating = True
End Sub

How can I modify it so that it looks to two columns where both rows
have to have a zero value so that the row can be deleted?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Delete a row based on more than one condtion

Try this:

RngColAB(c).offset(0,1) 'One cell to the right
RngColAB(c).offset(1,0) 'One cell below

HTH,
Barb Reinhardt

If RngColAB(c).Value = 0 Then _

"Opal" wrote:

I am using the following code to delete a row in a spreadsheet based
on the value (zero) in that row:

Sub RemoveZero()
Dim RngColAB As Range
Dim c As Long
Application.ScreenUpdating = False
Set RngColAB = Range("AB2", Range("AB" & Rows.Count).End(xlUp))
For c = RngColAB.Count To 1 Step -1
RngColAB(c).Value = Application.Trim(RngColAB(c))
If RngColAB(c).Value = 0 Then _
RngColAB(c).EntireRow.Delete
Next c
Application.ScreenUpdating = True
End Sub

How can I modify it so that it looks to two columns where both rows
have to have a zero value so that the row can be deleted?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Delete a row based on more than one condtion

On Aug 25, 7:38 pm, Barb Reinhardt
wrote:
Try this:

RngColAB(c).offset(0,1) 'One cell to the right
RngColAB(c).offset(1,0) 'One cell below

HTH,
Barb Reinhardt



If RngColAB(c).Value = 0 Then _

"Opal" wrote:
I am using the following code to delete a row in a spreadsheet based
on the value (zero) in that row:


Sub RemoveZero()
Dim RngColAB As Range
Dim c As Long
Application.ScreenUpdating = False
Set RngColAB = Range("AB2", Range("AB" & Rows.Count).End(xlUp))
For c = RngColAB.Count To 1 Step -1
RngColAB(c).Value = Application.Trim(RngColAB(c))
If RngColAB(c).Value = 0 Then _
RngColAB(c).EntireRow.Delete



Thank you, both. That worked really well.

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
condtion for entering date Vijaya Setting up and Configuration of Excel 1 May 14th 09 12:33 PM
delete row based on value of ... jatman New Users to Excel 1 October 27th 08 04:02 AM
How to reset Excel 2002 to first run condtion Phil M. Excel Discussion (Misc queries) 9 July 27th 07 01:46 PM
sumif with 2 condtion Daoud Fakhry Excel Worksheet Functions 3 November 6th 06 12:55 PM
delete based on flow23 Excel Discussion (Misc queries) 1 July 3rd 06 12:23 PM


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