Link to home
Start Free TrialLog in
Avatar of afro4cboss
afro4cboss

asked on

Excel 2007 Routine Requested to Delete Matching Records

All,

  I have a list of servers in Column A. In columns B and more; I have a list of applications on each server (with the servers named in each 'entry' [row]).
 
  What code/procedure can be constructed to search all then entries in column B for each server (or every item [one word per row]) in Column A against every row in ColumnB; and remove the server(name) when there is any match; only leaving Column A with names not found in Column B data?

  This 'process' compares both colums. If any of the servernames (column A) match any 'records' in column B; delete that servername (from Column A). Repeat for all elements in Column A.


Any ideas?


Marty Nickison
Avatar of Harry Lee
Harry Lee
Flag of Canada image

Can you check if the following macro would work for you?

PLEASE make a backup before testing.

Sub CleanUpRecord()
Dim i As Long, ws As Worksheet, ChkRng As Range, Chk As Range, ChkRnglr As Long

Application.ScreenUpdating = False
Set ws = ActiveSheet
ChkRnglr = ws.Cells(Rows.Count, 2).End(xlUp).Row
Set ChkRng = ws.Range(Cells(1, 2), Cells(ChkRnglr, 2))

For i = ws.Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
    For Each Chk In ChkRng
        If ws.Cells(i, 1).Value = Chk.Value Then
            ws.Cells(i, 1).Delete shift:=xlUp
        End If
    Next
Next
Application.ScreenUpdating = True
End Sub

Open in new window

Avatar of afro4cboss
afro4cboss

ASKER

Is there anyway to use a nested IFxxx... or MATCH statement to do this?
You would end up with a new column, and a lot of blank rows if you want to use If and Match statement to do so.

Is that what you want?
Yes, having a new column would not hurt in any way.
In that case,

1) Add a column between Column A and Column B

2) In the newly added Column (the new Column B) B2, type in the following formula
  =IF(ISERROR(MATCH($A2,$C:$C,0)),A2,"")

3) In the newly added Column B3, type in the following formula
  =IF(AND(ISERROR(MATCH($A3,$C:$C,0)),ISERROR(MATCH($A3,$A$2:A2,0))),$A3,"")

5) Copy the formula in B3, all the way down your list.

That would force each server name to show up only once in the newly added column.

If you don't care if the server name shows up only once in the new column, instead of copying the formula in B3 all the way down, copy the formula in B2 all the way down.

The different between the two formulas is B2 formula does not check if the same server name exist in column B; while the B3 formula checks if the server name has already exist above.

When you are done, feel free to Cut and Paste the newly added column anywhere you want.
This will work, but only finds the exact match for the entire cell contents. That's part of the data set I want 'flagged'. But, for example:


  A                      C                 D

1  Dog                                    Dog
2  Cat                                     Cat Power
3  Whale                                I am a Whale


In your code above, the first search for A1 would find Dog. However, the code above would not find Cat Power in the B1 search...and I would need this flagged as well.



Any thoughts...we are almost there !!
ASKER CERTIFIED SOLUTION
Avatar of Harry Lee
Harry Lee
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for all the help. I created multiple tables and then setup a a query per 5 letters of the alphabet for the keywords to target. Then, I did an import to a 'final results' table of all the query results.