LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default compare two worksheets and delete rows

Mike, I modelled the code on what you had provided - it only checks for rows
in the same location. It is easily altered however to check for a match
anywhere in column 1 of Sheet2.

Dim sh1 as Worksheet, sh2 as Worksheet
Dim i as Long, rng as Range
Dim lastRow as Long
set sh2 = Worksheets(2)
set sh1 = Worksheets(1)
lastrow = sh1.Cells(Rows.Count, "A").End(xlUp).Row
With sh2
set rng2 = .Range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
End With
For i = lastrow To 1 Step -1
If Application.Countif(rng2,Sh1.Cells(i,"A").Value)0 then
sh1.Rows(i).Delete
End If
Next


--
Regards,
Tom Ogilvy



wrote in message
oups.com...
Quick questions...the macro runs fine with some small test data. I ran
the macro where sh2 had 547 rows and sh1 had 2800 rows. There was a
dupe on sh1 and sh2. On row 2820 sh1 and on row 547 sh2. However the
macro did not remove the row in sh1.

Any ideas why?



 
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
Compare Rows and delete duplicate records Dizzlews Excel Worksheet Functions 3 August 12th 08 11:16 PM
Help! -How to compare two worksheets; multiple rows of data=result EricZ Excel Worksheet Functions 1 March 26th 08 07:09 PM
Compare 1st 8 digits of rows in three worksheets NeedExcelHelp07 Excel Worksheet Functions 0 January 30th 08 08:47 PM
Add or Delete Rows in Protected worksheets NH Excel Discussion (Misc queries) 0 March 16th 06 05:15 PM
Using VBA to delete certain worksheets rows avilla Excel Programming 1 September 7th 04 04:34 PM


All times are GMT +1. The time now is 04:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"