PC Review


Reply
Thread Tools Rate Thread

Delete row macro

 
 
AT
Guest
Posts: n/a
 
      18th Mar 2008
Hi,
I need a macro that can delete certain rows as follows:
If B(X)=B(X+1) AND C(X)=C(X+1) AND D(X) =0 THEN
Delete row(X)
Else do nothing

Is it possible?

 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      18th Mar 2008
Hi,

The logic fior this interprets as
If B1 = B2 And C1 = C2 And D1 = 0 Then
delete the row so try this

Sub delete_Me()
Lastrow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
For x = Lastrow To 1 Step -1
If Range("B" & (x)) = Range("B" & (x + 1)) _
And Range("C" & (x)) = Range("C" & (x + 1)) _
And (Range("D" & (x))) = "0" Then
Rows(x).Delete
End If
Next
End Sub

Mike



"AT" wrote:

> Hi,
> I need a macro that can delete certain rows as follows:
> If B(X)=B(X+1) AND C(X)=C(X+1) AND D(X) =0 THEN
> Delete row(X)
> Else do nothing
>
> Is it possible?
>

 
Reply With Quote
 
AT
Guest
Posts: n/a
 
      18th Mar 2008
Thanks.
Worked fine!

"Mike H" wrote:

> Hi,
>
> The logic fior this interprets as
> If B1 = B2 And C1 = C2 And D1 = 0 Then
> delete the row so try this
>
> Sub delete_Me()
> Lastrow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
> For x = Lastrow To 1 Step -1
> If Range("B" & (x)) = Range("B" & (x + 1)) _
> And Range("C" & (x)) = Range("C" & (x + 1)) _
> And (Range("D" & (x))) = "0" Then
> Rows(x).Delete
> End If
> Next
> End Sub
>
> Mike
>
>
>
> "AT" wrote:
>
> > Hi,
> > I need a macro that can delete certain rows as follows:
> > If B(X)=B(X+1) AND C(X)=C(X+1) AND D(X) =0 THEN
> > Delete row(X)
> > Else do nothing
> >
> > Is it possible?
> >

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      18th Mar 2008
your welcome

"AT" wrote:

> Thanks.
> Worked fine!
>
> "Mike H" wrote:
>
> > Hi,
> >
> > The logic fior this interprets as
> > If B1 = B2 And C1 = C2 And D1 = 0 Then
> > delete the row so try this
> >
> > Sub delete_Me()
> > Lastrow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
> > For x = Lastrow To 1 Step -1
> > If Range("B" & (x)) = Range("B" & (x + 1)) _
> > And Range("C" & (x)) = Range("C" & (x + 1)) _
> > And (Range("D" & (x))) = "0" Then
> > Rows(x).Delete
> > End If
> > Next
> > End Sub
> >
> > Mike
> >
> >
> >
> > "AT" wrote:
> >
> > > Hi,
> > > I need a macro that can delete certain rows as follows:
> > > If B(X)=B(X+1) AND C(X)=C(X+1) AND D(X) =0 THEN
> > > Delete row(X)
> > > Else do nothing
> > >
> > > Is it possible?
> > >

 
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
Converting a “Delete Column” Macro to a “Delete Row” Macro cardan Microsoft Excel Programming 7 15th May 2010 06:38 PM
Macro to delete current row AND delete objects also located in thatrow. Tonso Microsoft Excel Discussion 3 27th Jan 2009 02:43 PM
Re: Macro to delete sheets and saves remaining file does not properly delete module gazornenplat Microsoft Excel Programming 0 22nd Jun 2005 01:12 AM
Macro to delete sheets and saves remaining file does not properly delete module pherrero Microsoft Excel Programming 7 21st Jun 2005 05:16 PM
macro to delete entire rows when column A is blank ...a quick macro vikram Microsoft Excel Programming 4 3rd May 2004 08:45 PM


Features
 

Advertising
 

Newsgroups
 


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