Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Calling all MVPs! Macro to delete non matches b/t two lists. Thank

I need a macro that deletes rows in tab "A" if the IDs in column A do not
match those in column "A" of the master list on tab "B". So, if the IDs
match, then they're kept; non matches are deleted.
I tried to modify a delete duplicates macro I use regularly, but have had no
luck.
Thanks for your help.
Excel User
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Calling all MVPs! Macro to delete non matches b/t two lists. Thank

Sub DeleteRows()
Dim rng as Range, i as Long
Dim lastrow as Long
With worksheets("B")
set rng = .Range(.cells(1,1),.cells(rows.count,1).End(xlup))
End with
with worksheets("A")
lastrow = .Cells(rows.count,1).End(xlup).Row
for i = lastrow to 1 step -1
if application.Countif(rng,.cells(i,1)) = 0 then
.rows(i).Delete
end if
Next i
End with
End Sub

Adjust to match your situation

Test on a copy of your data

--
Regards,
Tom Ogilvy


"Excel User" wrote in message
...
I need a macro that deletes rows in tab "A" if the IDs in column A do not
match those in column "A" of the master list on tab "B". So, if the IDs
match, then they're kept; non matches are deleted.
I tried to modify a delete duplicates macro I use regularly, but have had

no
luck.
Thanks for your help.
Excel User



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Calling all MVPs! Macro to delete non matches b/t two lists. T

this works! thanks for your valuable guidance!
EU

"Tom Ogilvy" wrote:

Sub DeleteRows()
Dim rng as Range, i as Long
Dim lastrow as Long
With worksheets("B")
set rng = .Range(.cells(1,1),.cells(rows.count,1).End(xlup))
End with
with worksheets("A")
lastrow = .Cells(rows.count,1).End(xlup).Row
for i = lastrow to 1 step -1
if application.Countif(rng,.cells(i,1)) = 0 then
.rows(i).Delete
end if
Next i
End with
End Sub

Adjust to match your situation

Test on a copy of your data

--
Regards,
Tom Ogilvy


"Excel User" wrote in message
...
I need a macro that deletes rows in tab "A" if the IDs in column A do not
match those in column "A" of the master list on tab "B". So, if the IDs
match, then they're kept; non matches are deleted.
I tried to modify a delete duplicates macro I use regularly, but have had

no
luck.
Thanks for your help.
Excel User




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
How can I delete all matches in a workbook? LiveUser Excel Worksheet Functions 4 January 18th 08 08:55 PM
Compare lists and highlight matches srain001 Excel Discussion (Misc queries) 3 March 2nd 07 06:23 PM
Compare lists and highlight matches srain001 Excel Discussion (Misc queries) 2 March 1st 07 02:01 PM
An Algorithm that matches two lists DDONNI[_2_] Excel Programming 0 October 25th 04 02:25 PM
An Algorithm that matches two lists DDONNI Excel Programming 1 October 19th 04 12:16 PM


All times are GMT +1. The time now is 06:46 AM.

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"