PC Review


Reply
Thread Tools Rate Thread

Delete a row based on more than one condtion

 
 
Opal
Guest
Posts: n/a
 
      25th Aug 2007
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?

 
Reply With Quote
 
 
 
 
=?Utf-8?B?cDQ1Y2Fs?=
Guest
Posts: n/a
 
      26th Aug 2007
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?
>
>

 
Reply With Quote
 
=?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?=
Guest
Posts: n/a
 
      26th Aug 2007
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?
>
>

 
Reply With Quote
 
Opal
Guest
Posts: n/a
 
      27th Aug 2007
On Aug 25, 7:38 pm, Barb Reinhardt
<BarbReinha...@discussions.microsoft.com> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
condtion for entering date Vijaya Microsoft Excel Setup 1 14th May 2009 12:33 PM
How to reset Excel 2002 to first run condtion Phil M. Microsoft Excel Misc 9 27th Jul 2007 01:46 PM
sumif with 2 condtion =?Utf-8?B?RGFvdWQgRmFraHJ5?= Microsoft Excel Worksheet Functions 3 6th Nov 2006 12:55 PM
Re: Form setup: Required field based on condtion of another field Max Microsoft Excel Worksheet Functions 0 19th May 2004 03:23 AM
Regular Expression that matchs more than one condtion Earl Teigrob Microsoft C# .NET 2 7th May 2004 05:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:06 PM.