Find And replace macro
"James" wrote:
1. Column A, titled "Phrase" contains 500 or more alphanumeric Strings
2. Column B, titled "Find and Delete" contains a single word or phrase
(i.e., different phrases throughout the column)
The macro would go row by row, essentially Finding the values that are in
Column B and, if it finds a match, it would delete that word or phrase
from Column A.
In the example below, the values "Apple" and "Big" would be left remaining
in column A, after the macro runs.
(A1)Phrase (B1)Find and Delete
(A2)Apple Jack (B2) Jack
(A3)Big Bug (B3) Bug
Here is my solution:
'
' Remember to click on Tools-References.
' Then select Microsoft VBScript Regular Expressions 5.5
'
Sub TryThis()
Dim ptrn As String
Dim re As Object
Dim i As Integer
Set re = New RegExp
For i = 1 To 500
re.Pattern = Sheet1.Cells(i + 1, 2)
re.IgnoreCase = True
re.Global = True
Sheet1.Cells(i + 1, 1) = re.Replace(Sheet1.Cells(i + 1, 1), "")
Next
End Sub
|