compare columns on different sheets (same workbook) and delete rows where no match found

davidmyers

Board Regular
Joined
Jan 29, 2017
Messages
88
Office Version
  1. 2016
Platform
  1. Windows
Hi,
Can't find a solution, and need a little help.
If possible I'd like to this with a formula.
Compare values in

Complaints!B2:B1350 (Whole column starting B2) In this range the values are not unique - same value on many rows.

with the range:

Memp-Only!A2:A143 (Whole column starting A2) Here all values are unique

I want to delete all rows in Complaints sheet that do not have a matching value in Memp-Only

Thanks for any help
David
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
davidmyers,

So that we can get it right on the first try, can we see your actual raw data workbook, worksheets Complaints, and, Memp-Only?

You can post your workbook/worksheets to the following free site (sensitive data changed), mark the workbook for sharing, and, provide us with a link to your workbook:

https://dropbox.com
 
Upvote 0
If possible I'd like to this with a formula.

I want to delete all rows ...
Given that a formula cannot delete a row from a worksheet ..
- a macro could delete rows
- formulas coupled with a manual process could delete rows
- formulas could create a new list somewhere else (where?) that excluded the values you talk about deleting

Which of the above appeals? Or do you have something else altogether in mind?
 
Upvote 0
Thanks Peter,
I found this piece of vba code that did the job:

Code:
Sub DeleteNotMatch()
Dim i As Integer
Const sh1Col As String = "B" ' << sheet1 data in col A, change
Const sh2Col As String = "A" ' << sheet2 data in col A, change
Dim ws1 As Worksheet, ws2 As Worksheet
Dim r1 As Long, r2 As Long
Set ws1 = Sheets("Complaints")
Set ws2 = Sheets("Memp-Only")
r1 = ws1.Cells(Rows.Count, sh1Col).End(xlUp).Row
r2 = ws2.Cells(Rows.Count, sh2Col).End(xlUp).Row
For i = r1 To 2 Step -1
For Each r In ws2.Range(sh2Col & "2:" & sh2Col & r2)
If ws1.Cells(i, sh1Col).Value = r.Value Then GoTo myNext
Next r
ws1.Cells(i, sh1Col).EntireRow.Delete
myNext:
Next i
End Sub

Hope it helps someone
David
 
Upvote 0

Forum statistics

Threads
1,215,038
Messages
6,122,798
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top