VBA: Match Against a Blacklist and Delete Row??

ONEILR2192

New Member
Joined
Feb 16, 2013
Messages
2
Hello,

I'm trying to figure out a VBA solution to do the following:

If a cell in Sheet1 (my main sheet) range A7:A2007 is equal to any cell in Sheet2 (my blacklist) range A:A; Delete that entire row in Sheet1. (Both of these sheets are in the same workbook)

Because I'm already using some unrelated filters in the ranges specified I can't use a filter solution, I'm thinking it has to be a loop. I can't for the life of me figure out the language to accomplish this task. Hopefully some of the wizards around here can figure it out! PLEASE HELP!

Thanks!
 
Adomynous,

Thanks for the workbook/worksheets, and, the additional worksheets to help understand your requirements.

Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Code:
Sub Adomynous()
' hiker95, 11/19/2017, ME686091
Dim w1 As Worksheet, w2 As Worksheet
Dim a As Range, fa As Range, lra As Long, nr As Long
Application.ScreenUpdating = False
Set w1 = Sheets("Sheet1")
Set w2 = Sheets("Sheet2")
With w1
  lra = .Cells(Rows.Count, 1).End(xlUp).Row
  For Each a In .Range("A1:A" & lra)
    Set fa = w2.Columns(1).Find(a.Value, LookAt:=xlWhole)
    If Not fa Is Nothing Then
      a.Interior.Color = 65535
    Else
      nr = w2.Cells(w2.Rows.Count, "A").End(xlUp).Row + 1
      w2.Cells(nr, 1) = a.Value
      a.ClearContents
    End If
  Next a
  .Range("A1:A" & lra).SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm, and, answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Then run the Adomynous macro.
 
Last edited:
Upvote 0

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,215,247
Messages
6,123,857
Members
449,129
Latest member
krishnamadison

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