Skip to main content

How to delete rows not matching criteria on another sheet?

It may be not difficult for you to delete rows which do not match the criteria on the same sheet, but do you know any ways to delete the rows not matching criteria on another sheet as shown as below. Now I have two tricks that can help you quickly solve it.

Delete rows not matching criteria on another sheet with VBA

Delete rows not matching criteria on another sheet with Kutools for Excel

doc-delete-based-on-another-sheet-1 doc-delete-based-on-another-sheet-2 doc-right doc-delete-based-on-another-sheet-3
 Criteria(In Sheet 2)     Before(Sheet 1)          After(Sheet1)



arrow blue right bubble Delete rows not matching criteria on another sheet with VBA

There is a VBA code can help you delete rows not matching criteria on another sheet.

1. Press Alt + F11 to display the Microsoft Visual Basic for Applications window.

2. In the window, click Insert > Module to show a new module window, then copy the following VBA code into the module window.

VBA: Delete rows not matching criteria on another sheet in Excel.

Sub DeleteRow()
'Updateby20140618
Dim rng As Range
Dim Rng1 As Range, Rng2 As Range
Dim arr1 As Variant
Dim arr2 As Variant
Dim dic2 As Variant
Dim OutArr As Variant
xTitleId = "KutoolsforExcel"
Set Rng1 = Application.Selection
Set Rng1 = Application.InputBox("Range1 :", xTitleId, Rng1.Address, Type:=8)
Set Rng2 = Application.InputBox("Range2:", xTitleId, Type:=8)
Set Rng1 = Rng1.Columns(1)
Set Rng2 = Rng2.Columns(1)
Set dic2 = CreateObject("Scripting.Dictionary")
arr1 = Rng1.Value
arr2 = Rng2.Value
For i = 1 To UBound(arr2, 1)
    xKey = arr2(i, 1)
    dic2(xKey) = ""
Next
Rng1.ClearContents
OutArr = Rng1.Value
xIndex = 1
For i = 1 To UBound(arr1, 1)
    xKey = arr1(i, 1)
    If dic2.Exists(xKey) Then
        OutArr(xIndex, 1) = xKey
        xIndex = xIndex + 1
    End If
Next
Rng1.Value = OutArr
End Sub
3. Click Run, a KutoolsforExcel dialog pops up for you to select a range you want to delete the rows which are not matching criteria. See screenshot:

doc-delete-based-on-another-sheet-4

4. Click OK, and another dialog pops out for selecting the criteria in another sheet, see screenshot:

doc-delete-based-on-another-sheet-5

5. Now all rows not matching the criteria in another sheet are removed.


arrow blue right bubble Delete rows not matching criteria on another sheet with Kutools for Excel

If VBA code is a little difficult for you, you can have a try on Kutools for Excel’s Compare Ranges feature.

Kutools for Excel includes more than 300 handy Excel tools. Free to try with no limitation in 30 days. Get it Now

1. Select the sheet which you want to delete the rows which are not matching criteria. And click Kutools > Compare Ranges. See screenshot:

doc-delete-based-on-another-sheet-6

2. In the Compare Ranges dialog, click button in the Range B, and then you can select the criteria range you need. See screenshot:

doc-delete-based-on-another-sheet-7
doc-arrow
doc-delete-based-on-another-sheet-8

 

3. Then click OK, then back to the Compare Ranges dialog, check Different Value and Select entire rows. See screenshot:

doc-delete-based-on-another-sheet-9

4. Click Ok, and exit the Compare Ranges dialog. Then you see the value rows which are different from the criteria are selected.

doc-delete-based-on-another-sheet-10

5. Right click to click Delete from the context menu to delete the rows which are not matching the criteria on another sheet.

doc-delete-based-on-another-sheet-11

Click here for more information on Kutools for Excel’s Compare Ranges.


Relative Articles:

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...

Description


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
Comments (1)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Doesn't work with sheets that have multiple columns because it doesn't actually delete the row, just the cell.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations