View Full Version : Picking out the odd text


MI man
08-11-2010, 03:46 AM
Hi,

Can anybody crack this...!!!

I have 2 columns in Excel 2003. The rows of column A contains some text which is the same as the rows in column B, except for few differences.

Eg:
Row 1 of col A: This is a test line
Row 1 of col B: This may be a test line

I have many rows of such kind, and I need to find the odd words out.

Is there any possibility of writing a macro to churn out the odd words out into separate column, say Column C.

Eg:
Row 1 of col A: This is a test line
Row 1 of col B: This may be a test line
row 1 of col C: may be
Here 'may be' is the line that is different from col A

Help...!!!

Brianwarnock
08-11-2010, 03:55 AM
The difference are endless so the anser is probably no, howver if they are always adjacent cells as per your example then

=if(a2=b2," ","different")

would aid a visual check

Brian

chergh
08-11-2010, 04:12 AM
Something like this will work but it does have limitations such as if there are two occurences of a word in a phrase then it will not pick up the second occurence is missing.


Sub blah()

Dim arr1 As Variant
Dim arr2 As Variant

Dim blnMatch As Boolean

arr1 = Split(ThisWorkbook.Worksheets("Sheet1").Range("A1").Value, " ")
arr2 = Split(ThisWorkbook.Worksheets("Sheet1").Range("B1").Value, " ")

Dim strMissing As String

For i = LBound(arr2) To UBound(arr2)

blnMatch = False

For k = LBound(arr1) To UBound(arr1)

If arr2(i) = arr1(k) Then blnMatch = True

Next k


If blnMatch = False Then

strMissing = strMissing & ", " & arr2(i)

End If
Next i


ThisWorkbook.Worksheets("Sheet1").Range("C1").Value = strMissing


End Sub