finding words within other words with an Excel macro

5 pts.
Tags:
Excel 2007
Microsoft Excel
Microsoft Excel macros
column B has 2 letter words, the next 3 then 4 and so forth. I am looking to find the words in each column to the right to find all of theentrie that contain it and change the color of only the 2 or 3 or 4... letters in the new word for all words in each of the colomns to the right. Example: AA would find AAH, AAL, BAA, BAAL, BAASKAAP, ETC. 78 words total. the 2 letter words in column B could make the letters BLUE in the other columns and the 3 letter words GREEN in the other column and a different color for each column. Therre are 14 columns of words with 300,000 word combinations. I am looking for those smaller words within the larger words.

Thanks. We'll let you know when a new response is added.

It took me a few minutes but this Excel macro should do the trick for you. Bascially it’s going to go row by row, for all the columns and see if the values exist in any of the values in the columns to the right. Each source column should get a different column.

<pre> Dim i As Integer, j As Integer, Word As String, Col As Integer, SourceCol As Integer
i = 1
SourceCol = 65
Do Until Range(Chr(SourceCol) & 1).Value = “”
i = 1
Do Until Range(Chr(SourceCol) & i).Value = “”
Word = Range(Chr(SourceCol) & i).Value
j = 1
Col = 66
Do Until Range(Chr(Col) & j).Value = “”
j = 1
Do Until Range(Chr(Col) & j).Value = “”
Range(Chr(Col) & j).Select
If InStr(Range(Chr(Col) & j).Value, Word) <> 0 Then
Range(Chr(Col) & j).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ColorIndex = SourceCol – 60
End With
End If
j = j + 1
Loop
Col = Col + 1
j = 1
Loop
i = i + 1
Loop
SourceCol = SourceCol + 1
Loop</pre>