How to clean a column based on a list of blacklisted terms (without Macros) ?

ben74

New Member
Joined
Aug 26, 2016
Messages
3
Hi everyone,

Long time lurker, I've already learned a lot but I'm stuck here...


I need to clean a column based on a list of blacklisted terms stored in another column. Ideally the solution should be flexible enough to extend the list of blacklisted terms (col B) or the list of phrases to analyse (col A).
Also need to do this without running a MACRO.


Can someone kindly help me?

Example of the wanted behavior:

[TABLE="width: 482"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD]ORIGINAL-LIST[/TD]
[TD]BLACKLIST[/TD]
[TD]CLEANED-LIST[/TD]
[/TR]
[TR]
[TD]plural like greens should remain[/TD]
[TD]green[/TD]
[TD]plural like greens should remain[/TD]
[/TR]
[TR]
[TD]overgreen shouldn't be deleted[/TD]
[TD]red[/TD]
[TD]overgreen shouldn't be deleted[/TD]
[/TR]
[TR]
[TD]some greener stuff should stay[/TD]
[TD][/TD]
[TD]some greener stuff should stay[/TD]
[/TR]
[TR]
[TD]some string green stuff[/TD]
[TD][/TD]
[TD]plural like reds should remain[/TD]
[/TR]
[TR]
[TD]Green should get blacklisted too[/TD]
[TD][/TD]
[TD]overred shouldn't be deleted[/TD]
[/TR]
[TR]
[TD]And of course GREEN uppercase should be deleted[/TD]
[TD][/TD]
[TD]some reder stuff should stay[/TD]
[/TR]
[TR]
[TD]plural like reds should remain[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]overred shouldn't be deleted[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]some reder stuff should stay[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]some string red stuff[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Red should get blacklisted too[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]And of course RED uppercase should be deleted[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
So far this is what I have, see if this is what you want:

Excel Workbook
ABC
1ORIGINAL-LISTBLACKLISTCLEANED-LIST
2plural like greens should remaingreenplural like greens should remain
3overgreen shouldn't be deletedredovergreen shouldn't be deleted
4some greener stuff should stay*some greener stuff should stay
5some string green stuff*some string green stuff
6Green should get blacklisted too**
7And of course GREEN uppercase should be deleted**
8plural like reds should remain*plural like reds should remain
9overred shouldn't be deleted*overred shouldn't be deleted
10some reder stuff should stay*some reder stuff should stay
11some string red stuff*some string red stuff
12Red should get blacklisted too**
13And of course RED uppercase should be deleted**
Sheet1
 
Upvote 0
Thanks, any idea why it doesn't eliminate :


some string green stuff


and :


some string red stuff


from the clean list as it should ?


That's kinda weird...

I'm not sure using a FIND can do it, as a FIND will find any words/phrase that contain the STRING instead of the word (the goal is to blacklist words, not a chain of chars...)
 
Upvote 0
I cannot find a formula solution. Others on here may know of one. Is there a particular reason why you can't use a vba solution?
 
Upvote 0
If you can use a udf here is what I used courtesy of Rick Rothstein:

Excel Workbook
ABC
1ORIGINAL-LISTBLACKLISTCLEANED-LIST
2plural like greens should remaingreen*
3overgreen shouldn't be deletedred*
4some greener stuff should stay**
5some string green stuff**
6Green should get blacklisted too**
7And of course GREEN uppercase should be deleted**
8plural like reds should remain**
9overred shouldn't be deleted**
10some reder stuff should stay**
11some string red stuff**
12Red should get blacklisted too**
13And of course RED uppercase should be deleted**
Sheet1


Results:
Excel Workbook
ABC
1ORIGINAL-LISTBLACKLISTCLEANED-LIST
2plural like greens should remaingreenplural like greens should remain
3overgreen shouldn't be deletedredovergreen shouldn't be deleted
4some greener stuff should stay*some greener stuff should stay
5some string green stuff**
6Green should get blacklisted too**
7And of course GREEN uppercase should be deleted**
8plural like reds should remain*plural like reds should remain
9overred shouldn't be deleted*overred shouldn't be deleted
10some reder stuff should stay*some reder stuff should stay
11some string red stuff**
12Red should get blacklisted too**
13And of course RED uppercase should be deleted**
Sheet1


UDF:
Code:
Function ExactWordInString(Text As String, Word As String) As Boolean
     ExactWordInString = " " & UCase(Text) & " " Like "*[!A-Z]" & UCase(Word) & "[!A-Z]*"
End Function
 
Upvote 0
Thanks Michael !!

It kinda does what I need but it's not flexible at all (the list of forbidden/blacklisted words can change a lot).

Anyone has an idea to extend this formula to be able to handle a variable list of forbidden words ?

Thanks a lot !

Cheers,
 
Upvote 0
I am not sure if you changed your mind about a macro, but if so, here is how I did it:

Sheet 1 Setup
Excel Workbook
ABCD
1ORIGINAL-LISTBLACKLISTCLEANED-LISTIn List
2plural like greens should remaingreen**
3overgreen shouldn't be deletedred**
4some greener stuff should stay***
5some string green stuff***
6Green should get blacklisted too***
7And of course GREEN uppercase should be deleted***
8plural like reds should remain***
9overred shouldn't be deleted***
10some reder stuff should stay***
11some string red stuff***
12Red should get blacklisted too***
13And of course RED uppercase should be deleted***
Sheet1


After macro:
Excel Workbook
ABC
1ORIGINAL-LISTBLACKLISTCLEANED-LIST
2plural like greens should remaingreenplural like greens should remain
3overgreen shouldn't be deletedredovergreen shouldn't be deleted
4some greener stuff should stay*some greener stuff should stay
5some string green stuff*plural like reds should remain
6Green should get blacklisted too*overred shouldn't be deleted
7And of course GREEN uppercase should be deleted*some reder stuff should stay
8plural like reds should remain**
9overred shouldn't be deleted**
10some reder stuff should stay**
11some string red stuff**
12Red should get blacklisted too**
13And of course RED uppercase should be deleted**
Sheet1


macro:
Code:
Sub Cleaned_List()
Application.ScreenUpdating = False
Dim myval As String, lastcolumn As Long
Dim add1 As Long, add2 As Long
Dim xrow As Long, newlastrow As Long

Dim i As Long, lastrow As Long
Dim arr As Variant, item As Variant
lastrow = Cells(Rows.Count, 2).End(xlUp).Row
arr = Range(Cells(2, 2), Cells(lastrow, 2))

Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row).Copy Range("C2")
Range(Range("C2"), Range("C2").End(xlDown)).EntireColumn.AutoFit

For Each item In arr
    Range("D2:D" & Cells(Rows.Count, "C").End(xlUp).Row).Formula = _
   "=IF(OR(ISNUMBER(SEARCH({"" " & item & " ""},"" ""&C2&"" ""))),""Remove"",""Leave"")"

myval = "Remove"
newlastrow = Cells(Rows.Count, 3).End(xlUp).Row
lastcolumn = Cells.Find(What:="*", After:=Range("A1"), SearchOrder:= _
    xlByColumns, SearchDirection:=xlPrevious).Column
add1 = Columns(4).Find(What:=myval, LookIn:=xlValues, LookAt:=xlWhole).Row
xrow = add1

Do
If Cells(xrow + 1, 4).Value <> myval Then
add2 = xrow + 1
Exit Do
Else
xrow = xrow + 1
End If
Loop Until xrow = lastrow + 1
add2 = xrow

Range(Cells(add1, 3), Cells(add2, 4)).Select
Selection.Delete Shift:=xlUp

Next
Columns("D").Delete
Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Select
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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