sandcastl3s
New Member
- Joined
- Apr 10, 2016
- Messages
- 6
I have a text file with thousands of lines, one word per line. I'm trying to delete/remove lines that do not include one of multiple values, but not delete if there is a partial match of one of the values.
This almost exactly what I'm after:
except it looks for exact matches in the array. If the array is ("Will", "Jim") then it reduces
Will
William
Jim
Bob
Jim
Jimmy
James
to
Will
Jim
Jim
This deletes the items that include but are not exact matches of the values in the array.
I'm trying to figure out how to not delete the row/line if it contains a value in the array, either as an exact match or a partial match...which would reduce the above example list to
Will
William
Jim
Jim
Jimmy
Any ideas? I'm a bit of an excel novice and I can't work it out for the life of me. Thanks!
This almost exactly what I'm after:
Code:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">[COLOR=#00008B]
Sub[/COLOR][COLOR=#1A1A1A] Main[/COLOR][COLOR=#1A1A1A]()[/COLOR][COLOR=#1A1A1A]
[/COLOR][COLOR=#00008B]Dim[/COLOR][COLOR=#1A1A1A] dontDelete
dontDelete [/COLOR][COLOR=#1A1A1A]=[/COLOR][COLOR=#1A1A1A] Array[/COLOR][COLOR=#1A1A1A]([/COLOR][COLOR=#6B291B]"Will, "Jim[/COLOR][COLOR=#6B291B]"[/COLOR][COLOR=#1A1A1A])[/COLOR][COLOR=#1A1A1A]
[/COLOR][COLOR=#00008B]Dim[/COLOR][COLOR=#1A1A1A] i [/COLOR][COLOR=#00008B]As[/COLOR][COLOR=#00008B]Long[/COLOR][COLOR=#1A1A1A],[/COLOR][COLOR=#1A1A1A] j [/COLOR][COLOR=#00008B]As[/COLOR][COLOR=#00008B]Long[/COLOR][COLOR=#1A1A1A]
[/COLOR][COLOR=#00008B]Dim[/COLOR][COLOR=#1A1A1A] isThere [/COLOR][COLOR=#00008B]As[/COLOR][COLOR=#00008B]Boolean[/COLOR][COLOR=#1A1A1A]
[/COLOR][COLOR=#00008B]For[/COLOR][COLOR=#1A1A1A] i [/COLOR][COLOR=#1A1A1A]=[/COLOR][COLOR=#1A1A1A] Range[/COLOR][COLOR=#1A1A1A]([/COLOR][COLOR=#6B291B]"A"[/COLOR][COLOR=#1A1A1A]&[/COLOR][COLOR=#1A1A1A] Rows[/COLOR][COLOR=#1A1A1A].[/COLOR][COLOR=#1A1A1A]Count[/COLOR][COLOR=#1A1A1A]).[/COLOR][COLOR=#00008B]End[/COLOR][COLOR=#1A1A1A]([/COLOR][COLOR=#1A1A1A]xlUp[/COLOR][COLOR=#1A1A1A]).[/COLOR][COLOR=#1A1A1A]Row [/COLOR][COLOR=#00008B]To[/COLOR][COLOR=#6B291B]1[/COLOR][COLOR=#00008B]Step[/COLOR][COLOR=#1A1A1A]-[/COLOR][COLOR=#6B291B]1[/COLOR][COLOR=#1A1A1A]
[/COLOR][COLOR=#00008B]For[/COLOR][COLOR=#1A1A1A] j [/COLOR][COLOR=#1A1A1A]=[/COLOR][COLOR=#1A1A1A] LBound[/COLOR][COLOR=#1A1A1A]([/COLOR][COLOR=#1A1A1A]dontDelete[/COLOR][COLOR=#1A1A1A])[/COLOR][COLOR=#00008B]To[/COLOR][COLOR=#1A1A1A] UBound[/COLOR][COLOR=#1A1A1A]([/COLOR][COLOR=#1A1A1A]dontDelete[/COLOR][COLOR=#1A1A1A])[/COLOR][COLOR=#1A1A1A]
[/COLOR][COLOR=#00008B]If[/COLOR][COLOR=#1A1A1A] StrComp[/COLOR][COLOR=#1A1A1A]([/COLOR][COLOR=#1A1A1A]Range[/COLOR][COLOR=#1A1A1A]([/COLOR][COLOR=#6B291B]"A"[/COLOR][COLOR=#1A1A1A]&[/COLOR][COLOR=#1A1A1A] i[/COLOR][COLOR=#1A1A1A]),[/COLOR][COLOR=#1A1A1A] dontDelete[/COLOR][COLOR=#1A1A1A]([/COLOR][COLOR=#1A1A1A]j[/COLOR][COLOR=#1A1A1A]),[/COLOR][COLOR=#1A1A1A] vbTextCompare[/COLOR][COLOR=#1A1A1A])[/COLOR][COLOR=#1A1A1A]=[/COLOR][COLOR=#6B291B]0[/COLOR][COLOR=#00008B]Then[/COLOR][COLOR=#1A1A1A]
isThere [/COLOR][COLOR=#1A1A1A]=[/COLOR][COLOR=#6B291B]True[/COLOR][COLOR=#1A1A1A]
[/COLOR][COLOR=#00008B]End[/COLOR][COLOR=#00008B]If[/COLOR][COLOR=#1A1A1A]
[/COLOR][COLOR=#00008B]Next[/COLOR][COLOR=#1A1A1A] j
[/COLOR][COLOR=#00008B]If[/COLOR][COLOR=#00008B]Not[/COLOR][COLOR=#1A1A1A] isThere [/COLOR][COLOR=#00008B]Then[/COLOR][COLOR=#1A1A1A]
Range[/COLOR][COLOR=#1A1A1A]([/COLOR][COLOR=#6B291B]"A"[/COLOR][COLOR=#1A1A1A]&[/COLOR][COLOR=#1A1A1A] i[/COLOR][COLOR=#1A1A1A]).[/COLOR][COLOR=#1A1A1A]Delete shift[/COLOR][COLOR=#1A1A1A]:=[/COLOR][COLOR=#1A1A1A]xlUp
[/COLOR][COLOR=#00008B]End[/COLOR][COLOR=#00008B]If[/COLOR][COLOR=#1A1A1A]
isThere [/COLOR][COLOR=#1A1A1A]=[/COLOR][COLOR=#6B291B]False[/COLOR][COLOR=#1A1A1A]
[/COLOR][COLOR=#00008B]Next[/COLOR][COLOR=#1A1A1A] i
[/COLOR][COLOR=#00008B]End[/COLOR][COLOR=#00008B]Sub
[/COLOR]</code>
except it looks for exact matches in the array. If the array is ("Will", "Jim") then it reduces
Will
William
Jim
Bob
Jim
Jimmy
James
to
Will
Jim
Jim
This deletes the items that include but are not exact matches of the values in the array.
I'm trying to figure out how to not delete the row/line if it contains a value in the array, either as an exact match or a partial match...which would reduce the above example list to
Will
William
Jim
Jim
Jimmy
Any ideas? I'm a bit of an excel novice and I can't work it out for the life of me. Thanks!