PC Review


Reply
Thread Tools Rate Thread

Delete rows if not as range

 
 
Kashyap
Guest
Posts: n/a
 
      29th Mar 2009
I need to delete rows if sheet1 Column F not equal to Sheet3 G5:G10

I tried below code, but it works very very slow.. Actually there are around
25000+ records..

sub deleterows()
Set MySheet = Sheets("Sheet1")
LR = MySheet.Cells(Rows.Count,"F").End(xlup).Row
For i = LR to 2 Step -1
With Sheets("Sheet3")
If WorksheetFunction.Countif(.Range("G5:G10"),MySheet.Cells(i,"F"))>0 Then
MySheet.Rows(i).EntireRow.Delete
End If
End With
Next i
End Sub


Any better one..?
 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      29th Mar 2009
Dear Kashya, try replacing the CountIF function with Match.

If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

> I need to delete rows if sheet1 Column F not equal to Sheet3 G5:G10
>
> I tried below code, but it works very very slow.. Actually there are around
> 25000+ records..
>
> sub deleterows()
> Set MySheet = Sheets("Sheet1")
> LR = MySheet.Cells(Rows.Count,"F").End(xlup).Row
> For i = LR to 2 Step -1
> With Sheets("Sheet3")
> If WorksheetFunction.Countif(.Range("G5:G10"),MySheet.Cells(i,"F"))>0 Then
> MySheet.Rows(i).EntireRow.Delete
> End If
> End With
> Next i
> End Sub
>
>
> Any better one..?

 
Reply With Quote
 
Kashyap
Guest
Posts: n/a
 
      29th Mar 2009
Hi, would you please help me out with the formula..



"Jacob Skaria" wrote:

> Dear Kashya, try replacing the CountIF function with Match.
>
> If this post helps click Yes
> ---------------
> Jacob Skaria
>
>
> "Kashyap" wrote:
>
> > I need to delete rows if sheet1 Column F not equal to Sheet3 G5:G10
> >
> > I tried below code, but it works very very slow.. Actually there are around
> > 25000+ records..
> >
> > sub deleterows()
> > Set MySheet = Sheets("Sheet1")
> > LR = MySheet.Cells(Rows.Count,"F").End(xlup).Row
> > For i = LR to 2 Step -1
> > With Sheets("Sheet3")
> > If WorksheetFunction.Countif(.Range("G5:G10"),MySheet.Cells(i,"F"))>0 Then
> > MySheet.Rows(i).EntireRow.Delete
> > End If
> > End With
> > Next i
> > End Sub
> >
> >
> > Any better one..?

 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      29th Mar 2009
Dear Kashya

I have not done any major changes to your code. Please try and feedback.

Sub deleterows()
Application.ScreenUpdating = False
Set MySheet = Sheets("Sheet1")
Set MyRange = Sheets("Sheet3").Range("G5:G10")
LR = MySheet.Cells(Rows.Count, "F").End(xlUp).Row
For i = LR To 2 Step -1
If WorksheetFunction.CountIf(MyRange, MySheet.Cells(i, "F")) > 0 Then
MySheet.Rows(i).EntireRow.Delete
End If
Next i
Application.ScreenUpdating = True
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

> Hi, would you please help me out with the formula..
>
>
>
> "Jacob Skaria" wrote:
>
> > Dear Kashya, try replacing the CountIF function with Match.
> >
> > If this post helps click Yes
> > ---------------
> > Jacob Skaria
> >
> >
> > "Kashyap" wrote:
> >
> > > I need to delete rows if sheet1 Column F not equal to Sheet3 G5:G10
> > >
> > > I tried below code, but it works very very slow.. Actually there are around
> > > 25000+ records..
> > >
> > > sub deleterows()
> > > Set MySheet = Sheets("Sheet1")
> > > LR = MySheet.Cells(Rows.Count,"F").End(xlup).Row
> > > For i = LR to 2 Step -1
> > > With Sheets("Sheet3")
> > > If WorksheetFunction.Countif(.Range("G5:G10"),MySheet.Cells(i,"F"))>0 Then
> > > MySheet.Rows(i).EntireRow.Delete
> > > End If
> > > End With
> > > Next i
> > > End Sub
> > >
> > >
> > > Any better one..?

 
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
delete rows in a given range Wen Microsoft Excel Programming 1 30th Nov 2009 04:08 PM
Re: delete rows in a given range Rick Rothstein Microsoft Excel Programming 0 27th Nov 2009 05:06 PM
RE: delete rows in a given range Ryan H Microsoft Excel Programming 0 27th Nov 2009 04:20 PM
Delete a range of rows Lotto Microsoft Excel Discussion 2 27th Mar 2009 06:48 PM
Delete a range of rows Lotto Microsoft Excel Discussion 1 27th Mar 2009 06:40 PM


Features
 

Advertising
 

Newsgroups
 


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